Skip to content

Commit 6e59c73

Browse files
committed
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 <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>
1 parent 377a2cb commit 6e59c73

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/database/sql/sql.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2563,6 +2563,9 @@ type Rows struct {
25632563
}
25642564

25652565
func (rs *Rows) initContextClose(ctx, txctx context.Context) {
2566+
if ctx.Done() == nil && (txctx == nil || txctx.Done() == nil) {
2567+
return
2568+
}
25662569
ctx, rs.cancel = context.WithCancel(ctx)
25672570
go rs.awaitDone(ctx, txctx)
25682571
}

0 commit comments

Comments
 (0)