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

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

    XMLWordPrintable

Details

    Description

      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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: