Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-1455

Asynchronous servlet, onComplete() is not called when error occures

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Critical
    • Resolution: Done
    • Affects Version/s: 2.0.12.Final
    • Fix Version/s: 2.0.17.Final
    • Component/s: Servlet
    • Labels:
      None

      Description

      User impact: User relying implicitly on container calling onComplete() method will not be able to migrate app to 7.2 without change of source code.
      Workaround exists: Call AsyncContext.complete() explicitly in application code, e.g. in onError() method.

      Since undertow 2.0.12.Final the `AsyncListener#onComplete()` method is no longer called implicitly by container if error occures during asynchronous request processing in entering servlet. (Point iii. in servlet referenced specification section below)

      1. From javadoc [3] it is not clear how should these methods behave
      2. Specification clearly states container MUST call AsyncContext.complete(), therefore onComplete() should be called
        Chapter 2    The Servlet Interface
        
        Any errors or exceptions that may occur during the execution of the dispatch methods MUST be caught and hand led by the container as follows:
        
        i. invoke the AsyncListener.onError(AsyncEvent)  method for all instances of the AsyncListener  registered with the  ServletRequest  for which the AsyncContext was created and make the Throwable available via the AsyncEvent.getThrowable(). 
        
        ii. If none of the listeners called AsyncContext.complete or any of the AsyncContext.dispatch methods, then perform an error dispatch with a status code equal to HttpServletResponse.SC_INTERNAL_SERVER_ERROR
        and make the Throwable available as the value of the RequestDispatcher.ERROR_EXCEPTION request attribute. 
        
        iii. If no matching error page is found, or the error page does not call AsyncContext.complete() or any of the AsyncContext.dispatch methods, then the container MUST call AsyncContext.complete. 
        
      3. EAP passes TCKs. Most probably this aspect is not tested at all.
      4. Undertow Test [1] passes, but it makes explicit call to AsyncContext.complete therefore onComplete() is called after onError()
      5. Possible cause is described in [6] most probably https://github.com/undertow-io/undertow/commit/7f60713d8b3aeb9ce5713cda04a6397283605a5b

      [1] https://github.com/undertow-io/undertow/blob/ff4c9cf37872cb96070ba6a2fcbbaa6df291e390/servlet/src/test/java/io/undertow/servlet/test/listener/request/async/onError/AsyncListenerOnErrorTest.java
      [2] https://javaee.github.io/servlet-spec/downloads/servlet-4.0/servlet-4_0_FINAL.pdf
      [3] https://docs.oracle.com/javaee/7/api/javax/servlet/AsyncListener.html
      [4] https://developer.jboss.org/thread/279198
      [5] https://developer.jboss.org/thread/279198#986677
      [6] https://developer.jboss.org/message/986750#986750

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  swd847 Stuart Douglas
                  Reporter:
                  mchoma Martin Choma
                  Need Info from:
                  Stuart Douglas
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: