mirror of
https://github.com/golang/net.git
synced 2026-04-01 02:47:08 +09:00
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>
This commit is contained in:
committed by
Gopher Robot
parent
163d83654d
commit
b4c86550a5
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user