http3: keep QUIC connection after request context expires (#4854)

This commit is contained in:
Marten Seemann
2025-01-09 02:55:10 -08:00
committed by GitHub
parent 420f852f86
commit cc6b7faafb
2 changed files with 21 additions and 11 deletions

View File

@@ -333,9 +333,11 @@ var _ = Describe("Transport", func() {
cl2 := NewMockSingleRoundTripper(mockCtrl)
clientChan <- cl2
req1, err := http.NewRequest("GET", "https://quic-go.net/foobar.html", nil)
ctx, cancel := context.WithCancel(context.Background())
req1, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://quic-go.net/foobar.html", nil)
Expect(err).ToNot(HaveOccurred())
req2, err := http.NewRequest("GET", "https://quic-go.net/bar.html", nil)
req2, err := http.NewRequest(http.MethodGet, "https://quic-go.net/bar.html", nil)
Expect(err).ToNot(HaveOccurred())
conn := mockquic.NewMockEarlyConnection(mockCtrl)
@@ -344,14 +346,18 @@ var _ = Describe("Transport", func() {
count++
return conn, nil
}
testErr := context.Canceled
handshakeChan := make(chan struct{})
close(handshakeChan)
conn.EXPECT().HandshakeComplete().Return(handshakeChan).MaxTimes(2)
cl1.EXPECT().RoundTrip(req1).Return(nil, testErr)
cl1.EXPECT().RoundTrip(req1).DoAndReturn(
func(request *http.Request) (*http.Response, error) {
cancel()
return nil, context.Canceled
},
)
cl1.EXPECT().RoundTrip(req2).Return(&http.Response{Request: req2}, nil)
_, err = tr.RoundTrip(req1)
Expect(err).To(MatchError(testErr))
Expect(err).To(MatchError(context.Canceled))
rsp, err := tr.RoundTrip(req2)
Expect(err).ToNot(HaveOccurred())
Expect(rsp.Request).To(Equal(req2))