]> Cypherpunks repositories - gostls13.git/commitdiff
database/sql: check to see if ctx is cancelable before await
authorDaniel Theophanes <kardianos@gmail.com>
Mon, 26 Mar 2018 00:19:47 +0000 (17:19 -0700)
committerDaniel Theophanes <kardianos@gmail.com>
Tue, 27 Mar 2018 18:40:46 +0000 (18:40 +0000)
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 <kardianos@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Yasuhiro MATSUMOTO <mattn.jp@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/database/sql/sql.go

index 088e118df767d2e46a6b375c2cb92a5972f0256f..c8666653ba89eb4c49cb7593aa122e4169ee7118 100644 (file)
@@ -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)
 }