Fix intermittent Windows test flake in async httpx integration tests#1853
Merged
Conversation
BaseHTTPRequestHandler defaults to protocol_version "HTTP/1.0", which sets close_connection=True after every response. On Windows, the socket close can race with the async httpx client reading the response body, causing ReadError (Windows discards buffered TCP data on RST more aggressively than Linux). Setting protocol_version to "HTTP/1.1" keeps the connection alive, eliminating the race. The 30s timeout is a backstop against the handler blocking on readline if the client never closes the connection. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Committed-By-Agent: claude
With protocol_version set to HTTP/1.1, the server keeps the connection alive and reads the next request from the same socket. If the POST body isn't consumed, those bytes remain in the buffer and get misinterpreted as the next HTTP request line. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Committed-By-Agent: claude
With keep-alive, multiple requests are handled by the same BaseHTTPRequestHandler instance. Storing `self` in the queue meant all entries shared the same mutable object whose .headers/.path/.command reflect only the last request. Capture a snapshot at handle time instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Committed-By-Agent: claude
jar-stripe
marked this pull request as ready for review
July 24, 2026 17:51
jar-stripe
enabled auto-merge (squash)
July 24, 2026 17:51
xavdid
approved these changes
Jul 24, 2026
xavdid
left a comment
Member
There was a problem hiding this comment.
I'm not super familiar with this code, but it seems reasonable!
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Committed-By-Agent: claude
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.
Why?
BaseHTTPRequestHandler defaults to protocol_version "HTTP/1.0", which sets close_connection=True after every response. On Windows, the socket close can race with the async httpx client reading the response body, causing ReadError (Windows discards buffered TCP data on RST more aggressively than Linux).
Setting protocol_version to "HTTP/1.1" keeps the connection alive, eliminating the race. The 30s timeout is a backstop against the handler blocking on readline if the client never closes the connection.
Committed-By-Agent: claude
What?
BaseHTTPRequestHandlerprotocol version to HTTP/1.1, and timeout to 30sSee Also
Changelog