eclipse-ee4j / eclipse-ee4j/jersey
IllegalStateException with async REST service
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
I am seeing the below `IllegalStateException`s in our integration tests with an async REST service and so far we don't have any reliable reproduction.
```
java.lang.IllegalStateException: s=DISPATCHED i=false a=NOT_ASYNC
at org.eclipse.jetty.server.HttpChannelState.complete(HttpChannelState.java:681)
at org.eclipse.jetty.server.AsyncContextState.complete(AsyncContextState.java:99)
at org.glassfish.jersey.servlet.async.AsyncContextDelegateProviderImpl$ExtensionImpl.complete(AsyncContextDelegateProviderImpl.java:125)
at org.glassfish.jersey.servlet.internal.ResponseWriter.commit(ResponseWriter.java:197)
at org.glassfish.jersey.server.ContainerResponse.close(ContainerResponse.java:413)
at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:784)
at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:444)
at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:434)
at org.glassfish.jersey.server.ServerRuntime$AsyncResponder$3.run(ServerRuntime.java:934)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
at org.glassfish.jersey.server.ServerRuntime$AsyncResponder.resume(ServerRuntime.java:966)
at org.glassfish.jersey.server.ServerRuntime$AsyncResponder.resume(ServerRuntime.java:922)
at com.facebook.presto.server.TestingAsyncResponseHandler$1.onSuccess(TaskResource.java:408)
at com.google.common.util.concurrent.Futures$4.run(Futures.java:1135)
at io.airlift.concurrent.BoundedExecutor.drainQueue(BoundedExecutor.java:78)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
2017-10-03 05:13:16 WARNING Attempt to release request processing resources has failed for a request.
java.lang.IllegalStateException: AsyncContext completed and/or Request lifecycle recycled
at org.eclipse.jetty.server.AsyncContextState.state(AsyncContextState.java:54)
at org.eclipse.jetty.server.AsyncContextState.complete(AsyncContextState.java:99)
at org.glassfish.jersey.servlet.async.AsyncContextDelegateProviderImpl$ExtensionImpl.complete(AsyncContextDelegateProviderImpl.java:125)
at org.glassfish.jersey.servlet.internal.ResponseWriter.commit(ResponseWriter.java:197)
at org.glassfish.jersey.server.ContainerResponse.close(ContainerResponse.java:413)
at org.glassfish.jersey.server.ServerRuntime$Responder.release(ServerRuntime.java:810)
at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:435)
at org.glassfish.jersey.server.ServerRuntime$AsyncResponder$3.run(ServerRuntime.java:934)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
at org.glassfish.jersey.server.ServerRuntime$AsyncResponder.resume(ServerRuntime.java:966)
at org.glassfish.jersey.server.ServerRuntime$AsyncResponder.resume(ServerRuntime.java:922)
at com.facebook.presto.server.TestingAsyncResponseHandler$1.onSuccess(TaskResource.java:408)
at com.google.common.util.concurrent.Futures$4.run(Futures.java:1135)
at io.airlift.concurrent.BoundedExecutor.drainQueue(BoundedExecutor.java:78)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
```
The REST service code is [here](https://github.com/prestodb/presto/blob/master/presto-main/src/main/java/com/facebook/presto/server/TaskResource.java#L234), and the class where we do the async resume call is [here](https://github.com/airlift/airlift/blob/master/http-server/src/main/java/io/airlift/http/server/AsyncResponseHandler.java#L102) (in these stack traces `TestingAsyncResponseHandler` resumes the request, but it's the exact same code with `AsyncResponseHandler`). We are using Jersey 2.22.2 and Jetty 9.4.7.v20170914.
So far I have been investigating this issue with the Jetty team, at the same time I also wanted to get the opinions of Jersey experts and see whether this can be a Jersey issue. Any input is greatly appreciated.
Contributor guide
Assessment
This issue has not been assessed yet.