]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: add disabled test for Body Read/Close lock granularity
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 15 Jan 2014 21:12:32 +0000 (13:12 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 15 Jan 2014 21:12:32 +0000 (13:12 -0800)
Update #7121

R=golang-codereviews, gobot, dsymonds
CC=golang-codereviews
https://golang.org/cl/51750044

src/pkg/net/http/serve_test.go

index 8f382fa6ea11adc05944c4b5e621ec64dada3ef2..7a066ab07abc13aa7eab37d06b8fc65d7cbc76e4 100644 (file)
@@ -2148,6 +2148,57 @@ func TestTransportAndServerSharedBodyRace(t *testing.T) {
        (<-backendRespc).Body.Close()
 }
 
+// Test that a hanging Request.Body.Read from another goroutine can't
+// cause the Handler goroutine's Request.Body.Close to block.
+func TestRequestBodyCloseDoesntBlock(t *testing.T) {
+       t.Skipf("Skipping known issue; see golang.org/issue/7121")
+       if testing.Short() {
+               t.Skip("skipping in -short mode")
+       }
+       defer afterTest(t)
+
+       readErrCh := make(chan error, 1)
+       errCh := make(chan error, 2)
+
+       server := httptest.NewServer(HandlerFunc(func(rw ResponseWriter, req *Request) {
+               go func(body io.Reader) {
+                       _, err := body.Read(make([]byte, 100))
+                       readErrCh <- err
+               }(req.Body)
+               time.Sleep(500 * time.Millisecond)
+       }))
+       defer server.Close()
+
+       closeConn := make(chan bool)
+       defer close(closeConn)
+       go func() {
+               conn, err := net.Dial("tcp", server.Listener.Addr().String())
+               if err != nil {
+                       errCh <- err
+                       return
+               }
+               defer conn.Close()
+               _, err = conn.Write([]byte("POST / HTTP/1.1\r\nConnection: close\r\nHost: foo\r\nContent-Length: 100000\r\n\r\n"))
+               if err != nil {
+                       errCh <- err
+                       return
+               }
+               // And now just block, making the server block on our
+               // 100000 bytes of body that will never arrive.
+               <-closeConn
+       }()
+       select {
+       case err := <-readErrCh:
+               if err == nil {
+                       t.Error("Read was nil. Expected error.")
+               }
+       case err := <-errCh:
+               t.Error(err)
+       case <-time.After(5 * time.Second):
+               t.Error("timeout")
+       }
+}
+
 func TestResponseWriterWriteStringAllocs(t *testing.T) {
        ht := newHandlerTest(HandlerFunc(func(w ResponseWriter, r *Request) {
                if r.URL.Path == "/s" {