-
Bug
-
Resolution: Done
-
Major
-
3.9.1.Final, 4.5.3.Final
-
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.