From: Daniel Theophanes Date: Mon, 26 Mar 2018 00:19:47 +0000 (-0700) Subject: database/sql: check to see if ctx is cancelable before await X-Git-Tag: go1.11beta1~1085 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=6e59c73a9fe4eab3e09c6287f69c48837580dbb4;p=gostls13.git 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 --- 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) }