Skip to content

Commit

Permalink
http2: avoid extended CONNECT hang when connection breaks during startup
Browse files Browse the repository at this point in the history
Fixes golang/go#70658

Change-Id: Iaac5c7730a10afc8a8bb2e725746fa7387970582
Reviewed-on: https://go-review.googlesource.com/c/net/+/633277
Auto-Submit: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Antonio Ojea <aojea@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
  • Loading branch information
neild authored and gopherbot committed Feb 20, 2025
1 parent 163d836 commit b4c8655
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
10 changes: 7 additions & 3 deletions http2/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -2210,6 +2210,13 @@ func (rl *clientConnReadLoop) cleanup() {
}
cc.cond.Broadcast()
cc.mu.Unlock()

if !cc.seenSettings {
// If we have a pending request that wants extended CONNECT,
// let it continue and fail with the connection error.
cc.extendedConnectAllowed = true
close(cc.seenSettingsChan)
}
}

// countReadFrameError calls Transport.CountError with a string
Expand Down Expand Up @@ -2302,9 +2309,6 @@ func (rl *clientConnReadLoop) run() error {
if VerboseLogs {
cc.vlogf("http2: Transport conn %p received error from processing frame %v: %v", cc, summarizeFrame(f), err)
}
if !cc.seenSettings {
close(cc.seenSettingsChan)
}
return err
}
}
Expand Down
21 changes: 21 additions & 0 deletions http2/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5914,3 +5914,24 @@ func TestExtendedConnectClientWithoutServerSupport(t *testing.T) {
t.Fatalf("expected error errExtendedConnectNotSupported, got: %v", err)
}
}

// Issue #70658: Make sure extended CONNECT requests don't get stuck if a
// connection fails early in its lifetime.
func TestExtendedConnectReadFrameError(t *testing.T) {
tc := newTestClientConn(t)
tc.wantFrameType(FrameSettings)
tc.wantFrameType(FrameWindowUpdate)

req, _ := http.NewRequest("CONNECT", "https://dummy.tld/", nil)
req.Header.Set(":protocol", "extended-connect")
rt := tc.roundTrip(req)
tc.wantIdle() // waiting for SETTINGS response

tc.closeWrite() // connection breaks without sending SETTINGS
if !rt.done() {
t.Fatalf("after connection closed: RoundTrip still running; want done")
}
if rt.err() == nil {
t.Fatalf("after connection closed: RoundTrip succeeded; want error")
}
}

0 comments on commit b4c8655

Please sign in to comment.