From 6e59c73a9fe4eab3e09c6287f69c48837580dbb4 Mon Sep 17 00:00:00 2001 From: Daniel Theophanes Date: Sun, 25 Mar 2018 17:19:47 -0700 Subject: [PATCH] database/sql: check to see if ctx is cancelable before await Prevent queries from starting a goroutine if the context is not able to be canceled. Fixes #23879 Change-Id: I392047bd53d7f796219dd12ee11b07303658fdaf Reviewed-on: https://go-review.googlesource.com/102478 Run-TryBot: Daniel Theophanes TryBot-Result: Gobot Gobot Reviewed-by: Yasuhiro MATSUMOTO Reviewed-by: Brad Fitzpatrick --- src/database/sql/sql.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/database/sql/sql.go b/src/database/sql/sql.go index 088e118df7..c8666653ba 100644 --- a/src/database/sql/sql.go +++ b/src/database/sql/sql.go @@ -2563,6 +2563,9 @@ type Rows struct { } func (rs *Rows) initContextClose(ctx, txctx context.Context) { + if ctx.Done() == nil && (txctx == nil || txctx.Done() == nil) { + return + } ctx, rs.cancel = context.WithCancel(ctx) go rs.awaitDone(ctx, txctx) } -- 2.50.0