glassfish
  1. glassfish
  2. GLASSFISH-19364

web container does not call AsyncContext.complete() if dispatched servlet throws Exception

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.1.2.2
    • Fix Version/s: 4.0_b65
    • Component/s: web_container
    • Labels:
      None

      Description

      When an exception occurs in the execution of async dispatch(),
      web container MUST call AsyncContext.complete()
      if user application(AsyncListener or Error Page) does not call AsyncContext.complete().

      This behavior is written in the explanation of AsyncContext in Servlet 3.0 specification, section 2.3.3.3 Asynchronous processing.

      Any errors or exceptions that may occur during the execution of the dispatch methods MUST be caught and handled 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 caught 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.

      However, glassfish seems not to call AsyncContext.complete() if AsyncLister.onError() or Error Page does not call AsyncContext.complete().
      Therefore, my sample application always waits until async timeout(glassfish default 30 seconds).

      In addition, glassfish does not call complete() in case of async timeout of dispatch().
      But if I use start() method for async processing, complete() is called in case of async timeout.

      Is this a bug?
      Otherwise, is my understanding of the specification wrong?

        Activity

        Hide
        Shing Wai Chan added a comment -

        Sending AsyncContextImpl.java
        Sending Request.java
        Transmitting file data ..
        Committed revision 57176.

        Show
        Shing Wai Chan added a comment - Sending AsyncContextImpl.java Sending Request.java Transmitting file data .. Committed revision 57176.
        Hide
        winston_jack added a comment -

        I tried to apply the same fix(rev. 57176) to Glassfish 3.1.2.2.
        However, it didn't work well.
        It is because ErrorReportValve calls org.apache.catalina.connector.Response#reset(),
        and com.sun.grizzly.tcp.Response#reset().
        In com.sun.grizzly.tcp.Response#reset(), isSuspended flag is set to false,
        and Response is recycled.
        Therefore, org.apache.catalina.connector.Request#errorDispatchAndComplete(Throwable) throws IllegalStateException
        which is generated in com.sun.grizzly.tcp.Response#resume() because isSuspended is set to false.

        Do you have any good ideas to solve it?

        Show
        winston_jack added a comment - I tried to apply the same fix(rev. 57176) to Glassfish 3.1.2.2. However, it didn't work well. It is because ErrorReportValve calls org.apache.catalina.connector.Response#reset(), and com.sun.grizzly.tcp.Response#reset(). In com.sun.grizzly.tcp.Response#reset(), isSuspended flag is set to false, and Response is recycled. Therefore, org.apache.catalina.connector.Request#errorDispatchAndComplete(Throwable) throws IllegalStateException which is generated in com.sun.grizzly.tcp.Response#resume() because isSuspended is set to false. Do you have any good ideas to solve it?
        Hide
        Shing Wai Chan added a comment -

        In trunk, I have tested http://localhost:8080/asynctest/test and see the following in the log:
        [#|2012-12-20T12:12:20.368-0800|INFO|44.0|javax.enterprise.logging.stdout|_ThreadID=82;_ThreadName=glassfish-web-async-thread-1;_TimeMillis=1356034340368;_LevelValue=800;|onComplete|#]

        The async code has changed between 3.* and trunk.
        Can you try to use the the GlassFish in trunk.

        Show
        Shing Wai Chan added a comment - In trunk, I have tested http://localhost:8080/asynctest/test and see the following in the log: [#|2012-12-20T12:12:20.368-0800|INFO|44.0|javax.enterprise.logging.stdout|_ThreadID=82;_ThreadName=glassfish-web-async-thread-1;_TimeMillis=1356034340368;_LevelValue=800;|onComplete|#] The async code has changed between 3.* and trunk. Can you try to use the the GlassFish in trunk.
        Hide
        winston_jack added a comment -

        In Glassfish 4.0b65, this problem seemed to be fixed.
        Thank you for your contribution.

        However, I need the patch to Glassfish 3.x.

        While it may not be appropriate to ask in this comment,
        I want to know the roadmap (schedule) of Glassfish 3.x.
        Do you know Glassfish 3.1.2.3 (or 3.2) will be released?,
        and is this problem fixed in 3.1.2.3 (or 3.2)?

        If 3.1.2.3 (or 3.2) will be released,
        I'd like to report some problems about servlet asynchronous processing.

        Show
        winston_jack added a comment - In Glassfish 4.0b65, this problem seemed to be fixed. Thank you for your contribution. However, I need the patch to Glassfish 3.x. While it may not be appropriate to ask in this comment, I want to know the roadmap (schedule) of Glassfish 3.x. Do you know Glassfish 3.1.2.3 (or 3.2) will be released?, and is this problem fixed in 3.1.2.3 (or 3.2)? If 3.1.2.3 (or 3.2) will be released, I'd like to report some problems about servlet asynchronous processing.

          People

          • Assignee:
            Shing Wai Chan
            Reporter:
            winston_jack
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: