Skip to content

Let a single-use connection serve its request when the first stream is not 1 - #33

Merged
bogdanfinn merged 1 commit into
bogdanfinn:masterfrom
Mootjelh:single-use-first-stream
Oct 21, 2026
Merged

bogdanfinn merged 1 commit into
bogdanfinn:masterfrom
Mootjelh:single-use-first-stream

Conversation

@Mootjelh

Copy link
Copy Markdown

Fixes bogdanfinn/tls-client#289, along the lines michal-billtech proposed there.

A request with Connection: close gets a single-use connection. idleStateLocked counted that connection as spent once nextStreamID > 1, which assumes the first stream is 1. In fhttp it is not always: InitialStreamID, AllowHTTP and Priorities all move nextStreamID in newClientConn, before any request. So a fresh single-use connection reported that it could not take a request, RoundTrip got errClientConnUnusable, and the transport dialed a new connection, again and again. Firefox profiles start at stream 3, so this hits every one of them.

newClientConn now records where the connection starts (firstStreamID), and both checks in idleStateLocked compare against that instead of 1.

TestSingleUseConnServesItsRequestWhenTheFirstStreamIsNotOne runs four cases against a local HTTP/2 server and counts the connections the server sees:

  • first stream 1 with Connection: close, and InitialStreamID 3 without it. Both pass on master too, they are the controls
  • InitialStreamID 3 with Connection: close. On master: no response after 5s, 4 connections dialed
  • Priorities with Connection: close. Same on master

Each case must get a response over exactly one connection. Reverting either the comparison or the assignment fails the test.

The freshConn change only matters for the GetConn trace hook when the transport comes from ConfigureTransport. The test does not cover it, but it rests on the same assumption, so I changed it too.

go test ./... on Windows: the same 8 failures on master and on this branch (ServeFile, ServeContent, OmitHTTP2, cgi DirWindows), and none of them are in http2. ./http2 passes, also with -race.

Copilot AI balanced review requested due to automatic review settings October 21, 2026 01:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@bogdanfinn
bogdanfinn merged commit 4c3fb9f into bogdanfinn:master Oct 21, 2026
1 check passed
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.

[Bug]: [fhttp/http2] Connection: close never completes when the first stream is not 1 (InitialStreamID / Priorities)

3 participants