Uploaded image for project: 'WildFly'
  1. WildFly
  2. WFLY-3526

Servlet 3 - async-mode - onTimeout not triggered

    Details

    • Workaround Description:
      Hide

      1) Create a asynchronous servlet - added in the test description
      2) set the timeout to e.g. 5 sec
      3) start a process with AsyncContext#start – this process should take longer then the configured timeout (e.g. 20 sec)
      4) call the servlet in browser

      --> no timeout appear after 5 sec - the servlet runs 20 sec and then the result is displayed. No onTimeout-Event is ever triggered.

      Show
      1) Create a asynchronous servlet - added in the test description 2) set the timeout to e.g. 5 sec 3) start a process with AsyncContext#start – this process should take longer then the configured timeout (e.g. 20 sec) 4) call the servlet in browser --> no timeout appear after 5 sec - the servlet runs 20 sec and then the result is displayed. No onTimeout-Event is ever triggered.

      Description

      With asynchronous mode of servlets a long running process never times out.

      In my tests I have a async servlet which calls starts a long running process. That process take longer then the configured timeout. But here never a timeout comes. The long running process can complete.

      According to the spec, the servlet should run into a timeout and the AsyncListener#onTimeout method is called for registered listeners.

      But this never happens in Wildfly 8.

      Here is a test servlet

      AsyncServlet.java
      
      @WebServlet(urlPatterns = {"/AsyncServlet"}, asyncSupported = true)
      public class AsyncServlet extends HttpServlet {
          private static final long serialVersionUID = 1L;
      
          public AsyncServlet() {
              super();
          }
      
          @Override
          protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
              res.setContentType("text/html");
      
              final AsyncContext ac;
              if (req.isAsyncStarted()) {
                  ac = req.getAsyncContext();
              } else {
                  ac = req.startAsync();
              }
      
              ac.setTimeout(5000);
              ac.addListener(new AsyncListener() {
                  @Override
                  public void onTimeout(AsyncEvent event) throws IOException {
                      System.out.println("onTimeout");
                  }
                  @Override
                  public void onStartAsync(AsyncEvent event) throws IOException {
                      System.out.println("onStartAsync");
                  }
                  @Override
                  public void onError(AsyncEvent event) throws IOException {
                      System.out.println("onError");
                  }
                  @Override
                  public void onComplete(AsyncEvent event) throws IOException {
                      // end of async processing -> end of response time
                      System.out.println("onComplete");
                  }
              });
      
              // this processor takes longer then the timeout. e.g. 20 sec
              ac.start(new Runnable() {
      			@Override
      			public void run() {
      				try {
      					Thread.sleep(20*1000); // working...
      					ac.complete();
      				} catch (InterruptedException e) {
      					e.printStackTrace();
      				}
      			}
      		}); // start async processing
          }
      }
      
      

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                jason.greene Jason Greene
                Reporter:
                cwat-gugrill G√ľnther Grill
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: