http3: allow re-dialing of connection after a dial error (#4573)

* http3: do not cache dial error

* add an integration test

* http3: add a unit test for dial failures

---------

Co-authored-by: 世界 <i@sekai.icu>
This commit is contained in:
Marten Seemann
2024-06-23 12:38:49 +08:00
committed by GitHub
parent 10f8bd4e06
commit 2a082f973a
3 changed files with 56 additions and 0 deletions

View File

@@ -150,6 +150,29 @@ var _ = Describe("HTTP tests", func() {
Expect(resp.Header.Get("Content-Length")).To(Equal("6"))
})
It("re-establishes a QUIC connection after a dial error", func() {
var dialCounter int
testErr := errors.New("test error")
cl := http.Client{
Transport: &http3.RoundTripper{
TLSClientConfig: getTLSClientConfig(),
Dial: func(ctx context.Context, addr string, tlsConf *tls.Config, conf *quic.Config) (quic.EarlyConnection, error) {
dialCounter++
if dialCounter == 1 { // make the first dial fail
return nil, testErr
}
return quic.DialAddrEarly(ctx, addr, tlsConf, conf)
},
},
}
defer cl.Transport.(io.Closer).Close()
_, err := cl.Get(fmt.Sprintf("https://localhost:%d/hello", port))
Expect(err).To(MatchError(testErr))
resp, err := cl.Get(fmt.Sprintf("https://localhost:%d/hello", port))
Expect(err).ToNot(HaveOccurred())
Expect(resp.StatusCode).To(Equal(http.StatusOK))
})
It("detects stream errors when server panics when writing response", func() {
respChan := make(chan struct{})
mux.HandleFunc("/writing_and_panicking", func(w http.ResponseWriter, r *http.Request) {