Repository navigation
fix(server): reset body flag per request for keep-alive connections - #3
Open
2235864511 wants to merge 1 commit into
Open
2235864511 wants to merge 1 commit into
2235864511 wants to merge 1 commit into
Conversation
On a keep-alive connection the same handler instance serves every request, but setup() only runs once per connection, so _body_read stayed True after the first request and requests Patrick130306#2+ saw an empty body. Reset the flag in handle_one_request() before delegating to the base class.
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.
Problem
On a keep-alive (HTTP/1.1) connection, the same
BaseHTTPRequestHandlerinstance serves every request on that connection._body_readis initialized insetup(), which runs only once per connection, so after the first request sets it toTrue, every subsequent request on the same connection sees the stale flag and reads an empty body.Practical impact: clients that reuse connections (OpenAI/Anthropic SDKs,
requests.Session, ...) intermittently get their request body dropped on the second request of a connection, which is very confusing to debug.Fix
Reset
self._body_read = Falseat the start ofhandle_one_request()before delegating to the base class, so every request starts from a clean state. No behavior change for one-shot connections.I hit this while running the gateway behind a client that reuses connections; only the first request had a body.