Skip to content

Commit 135247d

Browse files
edrexmenghanl
authored andcommitted
fix server panic trying to send on stream as client disconnects #1111 (#1115)
1 parent 1c69e4c commit 135247d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

transport/handler_server.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,18 @@ func (a strAddr) String() string { return string(a) }
179179

180180
// do runs fn in the ServeHTTP goroutine.
181181
func (ht *serverHandlerTransport) do(fn func()) error {
182+
// Avoid a panic writing to closed channel. Imperfect but maybe good enough.
182183
select {
183-
case ht.writes <- fn:
184-
return nil
185184
case <-ht.closedCh:
186185
return ErrConnClosing
186+
default:
187+
select {
188+
case ht.writes <- fn:
189+
return nil
190+
case <-ht.closedCh:
191+
return ErrConnClosing
192+
}
193+
187194
}
188195
}
189196

0 commit comments

Comments
 (0)