eclipse-ee4j / eclipse-ee4j/jersey
Race condition in ChunkedOutput leads to unbounded queue growth.
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
When a ChunkedOutput is created inside a request handler and returned, ChunkedOutput.setContext has not yet been called, so requestScopeInstance, requestContext, and responseContext are all null. In this state, when ChunkedOutput.write is invoked, it does not (and can not!) wait for the written output to be flushed inside ChunkedOutput.flushQueue.
In our application, we saw this lead to a bad situation where the client/network were reading data slower than the server was writing it to the ChunkedOutput, and ChunkedOutput.setContext would get stuck inside flushQueue looping and reading from the queue while a background thread filled the queue on the other end. As a result, proper back-pressure was not applied to the writing thread and the heap ended up filling, leading to dropped connections and other badness.
It would be good to at least have the option of bounding the capacity of the queue in all cases so that no matter what in order setContext, write, etc. happen, we don't see this condition.
Contributor guide
Assessment
This issue has not been assessed yet.