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

AsyncOutputStream may never notify about completion, stalling a response unrecovrerably.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major Major
    • None
    • 4.5.8.Final
    • None
    • None
    • Undefined

      When using the AsyncOutputStream, if the completion callback to the application causes more data to be written, it's possible for the reference to the new async operation to be lost so the application will never be able to continue streaming.

      The cause seems to be this function in HttpServletResponseWrapper$DeferredOutputStream:

      private void flushQueue(ServletOutputStream sos)
            {
               if(lastAsyncOperation != null) {
                  lastAsyncOperation.future.complete(null);
                  lastAsyncOperation = null;
               }
      
               while(!asyncQueue.isEmpty() && sos.isReady()) {
                  lastAsyncOperation = asyncQueue.poll();
                  lastAsyncOperation.work(sos);
               }
          }
      

      The future.complete() call may cause a further write by the application, which will end up calling flushQueue() again, potentially setting a new value for lastAsyncOperation, if sos.isReady() becomes false after this write. The lastAsyncOperation reference will be set to null after complete() returns, so that the last enqueued operation will never be resolved.

            rchakrab Ranabir Chakraborty
            darnap Dario Napolitano (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: