Skip to content

Recheck HTTP/2 flow after acquiring read lock - #1163

Open
lordmauve wants to merge 1 commit into
pydantic:mainfrom
lordmauve:fix/http2-flow-control-race
Open

Recheck HTTP/2 flow after acquiring read lock#1163
lordmauve wants to merge 1 commit into
pydantic:mainfrom
lordmauve:fix/http2-flow-control-race

Conversation

@lordmauve

@lordmauve lordmauve commented Aug 26, 2026

Copy link
Copy Markdown

Fixes #1133.

When multiple HTTP/2 uploads exhaust the connection window, a task waiting in _wait_for_outgoing_flow() may queue behind another task on the read lock. That earlier read can deliver the WINDOW_UPDATE the queued task needs, but the queued task currently performs another blocking read without rechecking its window.

This change:

  • passes the flow-control stream ID into _receive_events();
  • rechecks the stream's effective outgoing window after acquiring the read lock and skips a redundant read when credit is already available;
  • applies the change to both the async implementation and its generated sync counterpart;
  • adds a deterministic regression test that restores connection credit during read-lock acquisition and verifies no further network read is attempted.

Tests:

  • scripts/check
  • uv run pytest tests/httpcore2 -q (238 passed)
  • async and sync HTTP/2 tests (39 passed)

Review in cubic

@codspeed-hq

codspeed-hq Bot commented Aug 26, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 17 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing lordmauve:fix/http2-flow-control-race (c5d8da2) with main (4c02c4b)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 4 files

Re-trigger cubic

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.

Concurrent HTTP/2 uploads deadlock in _wait_for_outgoing_flow

1 participant