Skip to content

fix(server): reset body flag per request for keep-alive connections - #3

Open
2235864511 wants to merge 1 commit into
Patrick130306:mainfrom
2235864511:fix/keepalive-body-reset
Open

2235864511 wants to merge 1 commit into
Patrick130306:mainfrom
2235864511:fix/keepalive-body-reset

Conversation

@2235864511

Copy link
Copy Markdown

Problem

On a keep-alive (HTTP/1.1) connection, the same BaseHTTPRequestHandler instance serves every request on that connection. _body_read is initialized in setup(), which runs only once per connection, so after the first request sets it to True, 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 = False at the start of handle_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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant