Skip to content

Fix intermittent Windows test flake in async httpx integration tests#1853

Merged
jar-stripe merged 4 commits into
masterfrom
jar/fix-windows-integration-test-flake
Jul 24, 2026
Merged

Fix intermittent Windows test flake in async httpx integration tests#1853
jar-stripe merged 4 commits into
masterfrom
jar/fix-windows-integration-test-flake

Conversation

@jar-stripe

@jar-stripe jar-stripe commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

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?

  • Sets the BaseHTTPRequestHandler protocol version to HTTP/1.1, and timeout to 30s
  • Updates tests to not assume we're dropping the connection between requests

See Also

Changelog

jar-stripe and others added 3 commits July 23, 2026 14:44
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
jar-stripe marked this pull request as ready for review July 24, 2026 17:51
@jar-stripe
jar-stripe requested a review from a team as a code owner July 24, 2026 17:51
@jar-stripe
jar-stripe requested review from kidus-stripe and removed request for a team July 24, 2026 17:51
@jar-stripe
jar-stripe enabled auto-merge (squash) July 24, 2026 17:51

@xavdid xavdid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super familiar with this code, but it seems reasonable!

Comment thread tests/test_integration.py Outdated
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Committed-By-Agent: claude
@jar-stripe
jar-stripe merged commit 6c6e373 into master Jul 24, 2026
17 checks passed
@jar-stripe
jar-stripe deleted the jar/fix-windows-integration-test-flake branch July 24, 2026 18:10
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.

2 participants