Uploaded image for project: 'JBoss Enterprise Application Platform'
  1. JBoss Enterprise Application Platform
  2. JBEAP-16009

(7.2.z) UNDERTOW-1455 - Asynchronous servlet, onComplete() is not called when error occures

    XMLWordPrintable

Details

    Description

      Customer impact: Customer 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

      Attachments

        Issue Links

          Activity

            People

              sdouglas1@redhat.com Stuart Douglas
              mchoma@redhat.com Martin Choma
              Stuart Douglas
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: