From: Damien Neil Date: Fri, 22 Jan 2021 02:24:55 +0000 (-0800) Subject: net/http: fix flaky TestDisableKeepAliveUpgrade X-Git-Tag: go1.16rc1~39 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7ece3a7b17ff637755dbe9e5687af22fd5f82168;p=gostls13.git net/http: fix flaky TestDisableKeepAliveUpgrade This test hijacks a connection. It was reading from the net.Conn returned by Hijack, not the bufio.ReadWriter, causing flaky failures when a read-ahead byte was held in the read buffer. Fixes #43073. Change-Id: Ic3e7f704fba9635fd851cb3c0c0c74e312b75f6e Reviewed-on: https://go-review.googlesource.com/c/go/+/285596 Trust: Damien Neil Run-TryBot: Damien Neil TryBot-Result: Go Bot Reviewed-by: Brad Fitzpatrick Reviewed-by: Anmol Sethi --- diff --git a/src/net/http/serve_test.go b/src/net/http/serve_test.go index 95e6bf4adb..f8687416fe 100644 --- a/src/net/http/serve_test.go +++ b/src/net/http/serve_test.go @@ -6460,13 +6460,15 @@ func TestDisableKeepAliveUpgrade(t *testing.T) { w.Header().Set("Connection", "Upgrade") w.Header().Set("Upgrade", "someProto") w.WriteHeader(StatusSwitchingProtocols) - c, _, err := w.(Hijacker).Hijack() + c, buf, err := w.(Hijacker).Hijack() if err != nil { return } defer c.Close() - io.Copy(c, c) + // Copy from the *bufio.ReadWriter, which may contain buffered data. + // Copy to the net.Conn, to avoid buffering the output. + io.Copy(c, buf) })) s.Config.SetKeepAlivesEnabled(false) s.Start()