Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-7575

@Suspended race condition

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.1.14
    • 3.2.2, 3.1.15
    • JAX-RS
    • None
    • Unknown

    Description

      There appears to be a race condition with the use of AsyncResponseImpl where my user thread can invoke resume() before initialSuspend is set to false by suspendContinuationIfNeeded() and therefore the resume() call does not actually resume the Continuation and returns true, indicating that the resume was successful even though it wasn't.

      I've spent all day trying to make sense of this problem and my understanding of how all of this works together is still a bit spotty, but it seems to me that AsyncResponseImpl.suspendContinuationIfNeeded() (or something similar) should be called before invoking the JAXRS method. Right now, that method is only called after the JAXRS method is invoked by JAXRSInvoker so the instance of AsyncResponse passed into the JAXRS method appears to not actually get suspended (or perhaps marked internally as suspended) until after the JAXRS method returns. If my async task happens to get finished very quickly and calls resume() before that happens, it fails silently.

      I seem to be able to circumvent this problem by running the following at the start of my JAXRS method (pseudo code):

      @POST
      @Path(....)
      void myJaxrsMethod(@Suspended AsyncResponse asyncResponse, ...) {
          if(asyncResponse instanceof AsyncResponseImpl) {
              ((AsyncResponseImpl)asyncResponse).suspendContinuationIfNeeded()
          }
          Runnable asyncTask = createAsyncTask(asyncResponse)
          submitAsyncTask(asyncTask)
      }
      

      which is why I suspect suspendContinuationIfNeeded() should be called before JAXRSInvoker invokes the JAXRS method.

      One of the things that made this really difficult to track down was that AsyncResponseImpl.resume() returns true even if the Continuation was not resumed! If you make it into doResumeFinal(), like was happening in my case, the return is always true even if cont.resume() is not called. So from user code, it looks like everything is ok, but the response never gets sent to the client.

      This seems somewhat related to the problems reported in CXF-7037

      Attachments

        1. CXF-7575.patch
          3 kB
          John Bellassai

        Activity

          People

            sergey_beryozkin Sergey Beryozkin
            jbellassai John Bellassai
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: