Commit 2bdc60f8 authored by Dave Cheney's avatar Dave Cheney

net/http: fix send on close channel error

Fixes #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
https://golang.org/cl/6445069
parent 122a558f
...@@ -538,7 +538,6 @@ func remoteSideClosed(err error) bool { ...@@ -538,7 +538,6 @@ func remoteSideClosed(err error) bool {
func (pc *persistConn) readLoop() { func (pc *persistConn) readLoop() {
defer close(pc.closech) defer close(pc.closech)
defer close(pc.writech)
alive := true alive := true
var lastbody io.ReadCloser // last response body, if any, read on this connection var lastbody io.ReadCloser // last response body, if any, read on this connection
...@@ -640,19 +639,24 @@ func (pc *persistConn) readLoop() { ...@@ -640,19 +639,24 @@ func (pc *persistConn) readLoop() {
} }
func (pc *persistConn) writeLoop() { func (pc *persistConn) writeLoop() {
for wr := range pc.writech { for {
if pc.isBroken() { select {
wr.ch <- errors.New("http: can't write HTTP request on broken connection") case wr := <-pc.writech:
continue if pc.isBroken() {
} wr.ch <- errors.New("http: can't write HTTP request on broken connection")
err := wr.req.Request.write(pc.bw, pc.isProxy, wr.req.extra) continue
if err == nil { }
err = pc.bw.Flush() err := wr.req.Request.write(pc.bw, pc.isProxy, wr.req.extra)
} if err == nil {
if err != nil { err = pc.bw.Flush()
pc.markBroken() }
if err != nil {
pc.markBroken()
}
wr.ch <- err
case <-pc.closech:
return
} }
wr.ch <- err
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment