]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: fix flaky TestDisableKeepAliveUpgrade
authorDamien Neil <dneil@google.com>
Fri, 22 Jan 2021 02:24:55 +0000 (18:24 -0800)
committerDamien Neil <dneil@google.com>
Fri, 22 Jan 2021 16:23:59 +0000 (16:23 +0000)
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 <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Anmol Sethi <nhooyr@gmail.com>
src/net/http/serve_test.go

index 95e6bf4adbaeec057324b96b73f00b9357439c47..f8687416fe96c019a80e7e2ae58740f2dd7508db 100644 (file)
@@ -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()