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

ExceptionMapper waits for timeout of AsynchronousResponse

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 2.3.7.Final
    • 2.3.3.Final, 2.3.5.Final, 2.3.6.Final
    • jaxrs
    • None

    Description

      When using AsynchronousResponse the client needs to wait for the specified timeout in case the ExceptionMapper is triggered. This is unexpected behaviour since the exception should be returned immediately. In fact this is done, but the client keeps waiting for the server to close the connection. (https://issues.jboss.org/browse/RESTEASY-721)

      I’ve looked into the 2.3.6 source code, where I believe to have found the issue: In the Servlet3AsyncHttpRequest.createAsynchronousResponse (line 40), the overridden method setResponse(Response) (line 52) never gets called when an exception is thrown during a request. When an exception is thrown during the invoker.invoke from the SynchronousDispatcher.getResponse (line 542), the exception will eventually get mapped via the handleInvokerException (line 557)method in the catch block. Which will call the writeFailure method followed by the writeJaxrsResponse (line 582) without ever doing a AsynContext.complete(). Hence, our application will only sent back a Response via the ExceptionMapper without ever calling the AbstractAsynchronousResponse.setResponse(Response) (line52). Thus the context.complete() will only get called after the TimeoutListener has timeout (if this has been set, which is set to infinity by default I believe).

      I’ve managed to find a solution to address this issue. Instead of handling the context.complete() by the AbstractAsynchronousResponse .setResponse (line 52), I’ve defined a completeAchronousResponse()in the HttpRequest interface, which will get called every time by the SynchronousDispatcher.wireJaxrsResponse. Thus Servlet3AsyncHttpRequest would override this method to call the AsynchContext.complete which would ensure an immediate response when handling an Exception for Asynchronous Requests.

      Of course, I am not familiar with the RestEasy code at all, so my solution is probably more of a workaround.

      Attachments

        Activity

          People

            patriot1burke@gmail.com Bill Burke (Inactive)
            nick_p_jira Nicolas Peters (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: