Skip to content

Commit

Permalink
conn: don't send message if context is already cancelled
Browse files Browse the repository at this point in the history
  • Loading branch information
guelfey committed Feb 13, 2022
1 parent 041560b commit d0c202b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,11 @@ func (conn *Conn) send(ctx context.Context, msg *Message, ch chan *Call) *Call {
call.ctx = ctx
call.ctxCanceler = canceler
conn.calls.track(msg.serial, call)
if ctx.Err() != nil {
// short path: don't even send the message if context already cancelled
conn.calls.handleSendError(msg, ctx.Err())
return call
}
go func() {
<-ctx.Done()
conn.calls.handleSendError(msg, ctx.Err())
Expand Down

0 comments on commit d0c202b

Please # to comment.