fix server panic trying to send on stream as client disconnects #1111 (#1115)

This commit is contained in:
Eric Drechsel
2017-05-15 12:41:55 -07:00
committed by Menghan Li
parent 1c69e4cae0
commit 135247d85c

View File

@ -179,12 +179,19 @@ func (a strAddr) String() string { return string(a) }
// do runs fn in the ServeHTTP goroutine.
func (ht *serverHandlerTransport) do(fn func()) error {
// Avoid a panic writing to closed channel. Imperfect but maybe good enough.
select {
case <-ht.closedCh:
return ErrConnClosing
default:
select {
case ht.writes <- fn:
return nil
case <-ht.closedCh:
return ErrConnClosing
}
}
}
func (ht *serverHandlerTransport) WriteStatus(s *Stream, st *status.Status) error {