eclipse-ee4j / eclipse-ee4j/jersey
Buffer overflow due to timeout with Netty + Jersey
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
When returning a large response using the Netty connector, a "Buffer overflow" error occurs. Switching from `jersey-container-netty-http` to `jersey-container-grizzly2-http` resolves the issue, so it appears to be specific to the netty connector.
Testing with a 521k response and Jersey 2.25.1, the buffer overflow occurs in org.glassfish.jersey.netty.connector.internal.JerseyChunkedInput#write at line 224\. The revelant code is:
```
private void write(Provider bufferSupplier) throws IOException {
checkClosed();
try {
boolean queued = queue.offer(bufferSupplier.get(), WRITE_TIMEOUT, TimeUnit.MILLISECONDS);
if (!queued) {
throw new IOException("Buffer overflow.");
}
} catch (InterruptedException e) {
throw new IOException(e);
}
}
```
The queue has a capacity of 8, and the offer timeout is 1000ms, which seems low.
Relevant portion of the stack trace:
```
Caused by: java.io.IOException: Buffer overflow.
at org.glassfish.jersey.netty.connector.internal.JerseyChunkedInput.write(JerseyChunkedInput.java:224)
at org.glassfish.jersey.netty.connector.internal.JerseyChunkedInput.write(JerseyChunkedInput.java:204)
at org.glassfish.jersey.message.internal.CommittingOutputStream.write(CommittingOutputStream.java:229)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$UnCloseableOutputStream.write(WriterInterceptorExecutor.java:299)
at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
```
#### Environment
OpenJDK 1.8.0_121
#### Affected Versions
[2.25.1]
Contributor guide
Research direction
Start in org.glassfish.jersey.netty.connector.internal.JerseyChunkedInput.write, especially the queue.offer call with its capacity of 8 and 1000ms timeout. Reproduce the issue with a 521k response on Jersey 2.25.1 using the Netty connector, then compare with the Grizzly2 connector and confirm the completed behavior no longer raises Buffer overflow.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100