Commits

Dave Cheney committed 26b62d1 Draft

net/http: fix send on close channel error

Fixes issue 3793.

Tested using GOMAXPROCS=81 which was able to trigger a panic
in TestStressSurpriseServerCloses continually on a Core i5.

R=fullung, bradfitz
CC=golang-dev
http://codereview.appspot.com/6445069

Comments (0)

Files changed (1)

src/pkg/net/http/transport.go

 
 func (pc *persistConn) readLoop() {
 	defer close(pc.closech)
-	defer close(pc.writech)
 	alive := true
 	var lastbody io.ReadCloser // last response body, if any, read on this connection
 
 }
 
 func (pc *persistConn) writeLoop() {
-	for wr := range pc.writech {
-		if pc.isBroken() {
-			wr.ch <- errors.New("http: can't write HTTP request on broken connection")
-			continue
+	for {
+		select {
+		case wr := <-pc.writech:
+			if pc.isBroken() {
+				wr.ch <- errors.New("http: can't write HTTP request on broken connection")
+				continue
+			}
+			err := wr.req.Request.write(pc.bw, pc.isProxy, wr.req.extra)
+			if err == nil {
+				err = pc.bw.Flush()
+			}
+			if err != nil {
+				pc.markBroken()
+			}
+			wr.ch <- err
+		case <-pc.closech:
+			return
 		}
-		err := wr.req.Request.write(pc.bw, pc.isProxy, wr.req.extra)
-		if err == nil {
-			err = pc.bw.Flush()
-		}
-		if err != nil {
-			pc.markBroken()
-		}
-		wr.ch <- err
 	}
 }