Skip to content

Commit 3775a5b

Browse files
authored
Merge pull request #312 from godbus/fix/conn_cancelled_context
conn: don't send message if context is already cancelled
2 parents 83fe796 + d0c202b commit 3775a5b

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

conn.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,11 @@ func (conn *Conn) send(ctx context.Context, msg *Message, ch chan *Call) *Call {
551551
call.ctx = ctx
552552
call.ctxCanceler = canceler
553553
conn.calls.track(msg.serial, call)
554+
if ctx.Err() != nil {
555+
// short path: don't even send the message if context already cancelled
556+
conn.calls.handleSendError(msg, ctx.Err())
557+
return call
558+
}
554559
go func() {
555560
<-ctx.Done()
556561
conn.calls.handleSendError(msg, ctx.Err())

0 commit comments

Comments
 (0)