Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-3046

ProviderHelper's writeTo stalls due to DeferredOutstream flush (on Tomcat)

XMLWordPrintable

      While using streaming responses using a RestEasy + Tomcat server, dnagarajan89  observed that the responses at times seems to gets truncated on the client side.

      On Looking into it I observed that this seems to happen as asyncWhile stalls during execution. As one of futures (AsyncOperation) in the chain of futures setup in the writeTo method, is lost during the execution of the flushStream operation in DeferredOutputStream, under the following conditions.

      Consider that an AsyncOperation, in the DeferredOutputStream, is not completed in doWork (its promise is not resolved, because the stream is no longer ready) it also happens to have dependent operations waiting on its chain(setup in writeTo). And it gets completed subsequently by the onWritePossible listener.

       

      But, its completion triggers the execution of the dependent AsyncOperations (until the stream is blocked again). And when it resumes post that, the ref it holds for the lastAsyncOperation is no longer the one it called complete on but the last async-operation in the dependent chain that got blocked by the stream.  Which it incorrectly resets causing the ref to an operation to be lost and stalling the pipeline.

      private void flushQueue(ServletOutputStream sos)
      {
         if(lastAsyncOperation != null) {
            lastAsyncOperation.future.complete(null);
            // ref changes after complete and gets reset before it can complete
            lastAsyncOperation = null;
         }
      .....

       

       

       

              jperkins-rhn James Perkins
              anthochris Antho D (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: