Skip to content

Commit

Permalink
Merge pull request #312 from godbus/fix/conn_cancelled_context
Browse files Browse the repository at this point in the history
conn: don't send message if context is already cancelled
  • Loading branch information
guelfey authored Feb 13, 2022
2 parents 83fe796 + d0c202b commit 3775a5b
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 3775a5b

Please sign in to comment.