From d0c202b21857745dae0667fbddaec5c4f489cd1c Mon Sep 17 00:00:00 2001 From: Georg Reinke Date: Sun, 13 Feb 2022 12:11:21 +0100 Subject: [PATCH] conn: don't send message if context is already cancelled --- conn.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/conn.go b/conn.go index 9c1fed3..69978ea 100644 --- a/conn.go +++ b/conn.go @@ -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())