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

@Suspended AsyncResponse timeout still runs, even if the response was resumed before

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 3.12.0.Final, 4.5.5.Final
    • 3.9.1.Final, 4.5.3.Final
    • jaxrs
    • None

      I have this simple JAX-RS resource using @Suspended AsyncResponse:

      public class AsyncResource {
          @GET
          public void get(@Suspended AsyncResponse response) {
              response.setTimeoutHandler(AsyncResource::timeoutResponse);
              response.setTimeout(2, TimeUnit.SECONDS);
      
              response.resume("Async hello");
          }
      
          private static void timeoutResponse(AsyncResponse response) {
              System.out.println("Timed out!");
              response.resume("Timeout response");
          }
      }
      

      The endpoint responds nicely with "Async hello", but after 2 seconds, I see "Timed out!" in the console log.

      I'm looking at https://github.com/resteasy/Resteasy/blob/master/resteasy-core/src/main/java/org/jboss/resteasy/plugins/server/servlet/Servlet3AsyncHttpRequest.java#L152 (because this is on Thorntail, which runs JAX-RS on top of servlet, same as WildFly) and the timeoutFuture created there is never cancelled. In my opinion, the future should be cancelled if the response is completed prior to the timeout.

      Alternatively, at least the handleTimeout method should check if the response is complete prior to invoking the handler. This is probably easier to implement, but also consumes more resources.

            rhn-engineering-ema Jim Ma
            lthon@redhat.com Ladislav Thon
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: