Repository navigation
Close keep-alive connections left with an unread request body - #71
Merged
Merged
Conversation
The JDK server discards only about 64KB of an unread body and then waits until Content-Length is satisfied, so a pipelined follow-up on that socket is never answered. Discard a small declared remainder so the connection can still be reused; otherwise send Connection: close and drop the socket without waiting for the rest of the body. Co-authored-by: ghosthack <ghosthack@users.noreply.github.com>
Interrupting the handler before the response stream closed reset the socket on Java 25 and discarded the reply the client had not read yet. Abandon the unread-body drain only after it blocks, which is the same path the empty and streaming responses already use. Co-authored-by: ghosthack <ghosthack@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
HTTP/1.1 keep-alive is the default. When a handler never reads the request body — a 413 because
Content-Lengthis over the form limit, a 405 or 404, or a success path that ignores the body — that body stays on the socket. The JDK server only discards about 64KB on the way out and will not read the next request until the declaredContent-Lengthhas arrived. A pipelined follow-up is swallowed, and the connection stays open until the rest of the body shows up or the idle timeout fires.Fix
On the way out of
Server.handle/HttpContext.finish, if the request body was not read through to EOF:Connection: closeand the socket is dropped, so the exchange is not left on the keep-alive path.The same rule applies to 413, 405, 404, and successful handlers that ignore the body. A body the handler already read through to EOF is unchanged and can stay keep-alive.
Tests
A socket client pipelines a follow-up GET after those cases (
ServerKeepAliveTest)../mvnw test— 373 tests, 0 failures.