eclipse-ee4j / eclipse-ee4j/jersey
JerseyEventSink continues to write to Response after the Container has completed the async context
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
Our product offers different REST APIs based on Jersey 2.26 running on Tomcat 8.5.
We are facing problems with asynchronous requests (using javax.ws.rs.sse.SseEventSink) which are closed by the client. If the async context is completed on server side, then it works as expected.
But when a client closes the connection, then the responses are recycled by Tomcat and reused for other requests. Tomcat will call onError method of any registered AsyncListener in AsyncContext. If none of the registered listeners are completing the AsyncContext, it will be done by the container. As far as I could see, Jersey does not register any listener to AsyncContext.
The asynchronous thread will just continue to write to the Response. If the Response is already reused by another request, then the SSE Event Sink is writing to this other Response. This leads to non-deterministic behaviour.
We have seen a wide range of unexpected resulte on the Client:
* Empty Response
* Truncated Responses
* CORS Problems (because response headers could not be written to a committed response)
* ...
As a workaround we had to disable the caching of http processors in Tomcat
See also the issue I have created for tomcat:
https://bz.apache.org/bugzilla/show_bug.cgi?id=61768
Contributor guide
Assessment
This issue has not been assessed yet.