Skip to content

Commit b4c8655

Browse files
neildgopherbot
authored andcommitted
http2: avoid extended CONNECT hang when connection breaks during startup
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>
1 parent 163d836 commit b4c8655

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

http2/transport.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -2210,6 +2210,13 @@ func (rl *clientConnReadLoop) cleanup() {
22102210
}
22112211
cc.cond.Broadcast()
22122212
cc.mu.Unlock()
2213+
2214+
if !cc.seenSettings {
2215+
// If we have a pending request that wants extended CONNECT,
2216+
// let it continue and fail with the connection error.
2217+
cc.extendedConnectAllowed = true
2218+
close(cc.seenSettingsChan)
2219+
}
22132220
}
22142221

22152222
// countReadFrameError calls Transport.CountError with a string
@@ -2302,9 +2309,6 @@ func (rl *clientConnReadLoop) run() error {
23022309
if VerboseLogs {
23032310
cc.vlogf("http2: Transport conn %p received error from processing frame %v: %v", cc, summarizeFrame(f), err)
23042311
}
2305-
if !cc.seenSettings {
2306-
close(cc.seenSettingsChan)
2307-
}
23082312
return err
23092313
}
23102314
}

http2/transport_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -5914,3 +5914,24 @@ func TestExtendedConnectClientWithoutServerSupport(t *testing.T) {
59145914
t.Fatalf("expected error errExtendedConnectNotSupported, got: %v", err)
59155915
}
59165916
}
5917+
5918+
// Issue #70658: Make sure extended CONNECT requests don't get stuck if a
5919+
// connection fails early in its lifetime.
5920+
func TestExtendedConnectReadFrameError(t *testing.T) {
5921+
tc := newTestClientConn(t)
5922+
tc.wantFrameType(FrameSettings)
5923+
tc.wantFrameType(FrameWindowUpdate)
5924+
5925+
req, _ := http.NewRequest("CONNECT", "https://dummy.tld/", nil)
5926+
req.Header.Set(":protocol", "extended-connect")
5927+
rt := tc.roundTrip(req)
5928+
tc.wantIdle() // waiting for SETTINGS response
5929+
5930+
tc.closeWrite() // connection breaks without sending SETTINGS
5931+
if !rt.done() {
5932+
t.Fatalf("after connection closed: RoundTrip still running; want done")
5933+
}
5934+
if rt.err() == nil {
5935+
t.Fatalf("after connection closed: RoundTrip succeeded; want error")
5936+
}
5937+
}

0 commit comments

Comments
 (0)