-
Notifications
You must be signed in to change notification settings - Fork 18k
database/sql: transaction leak #22976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Change https://golang.org/cl/81736 mentions this issue: |
Hi, will this fix be in go 1.9.3? |
Reopening to consider for 1.9.3. |
(But note that there may never be a 1.9.3 release, as 1.10 is expected in a few weeks.) |
CL 81736 OK for Go 1.9.3. |
Change https://golang.org/cl/88323 mentions this issue: |
When the user context which passed in (*DB)BeginTx is canceled or timeout, the current implementation could cause db transaction leak in some extreme scenario. Goroutine 1: Call (*DB) BeginTx begins a transaction with a userContext. In (*DB)BeginTx, a new goroutine (*Tx)awaitDone which monitor context and rollback tx if needed will be created Goroutine 2(awaitDone): block on tx.ctx.Done() Goroutine 1: Execute some insert or update sqls on the database Goroutine 1: Commit the transaction, (*Tx)Commit set the atomic variable tx.done to 1 Goroutine 3(maybe global timer): Cancel userContext which be passed in Tx Goroutine 1: (*Tx)Commit checks tx.ctx.Done(). Due to the context has been canceled, it will return context.Canceled or context.DeadlineExceeded error immediately and abort the real COMMIT operation of transaction Goroutine 2: Release with tx.ctx.Done() signal, execute (*Tx)rollback. However the atomic variable tx.done is 1 currently, it will return ErrTxDone error immediately and abort the real ROLLBACK operation of transaction Fixes #22976 Change-Id: I3bc23adf25db823861d91e33d3cca6189fb1171d Reviewed-on: https://go-review.googlesource.com/81736 Run-TryBot: Brad Fitzpatrick <[email protected]> Reviewed-by: Daniel Theophanes <[email protected]> Reviewed-on: https://go-review.googlesource.com/88323 Run-TryBot: Andrew Bonventre <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
go1.9.3 has been packaged and includes:
The release is posted at golang.org/dl. — golang.org/x/build/cmd/releasebot, Jan 22 21:02:58 UTC |
upgrade to avoid bug: golang/go#22976 Signed-off-by: Penghui Liao <[email protected]>
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go1.9.2 darwin/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?What did you do?
When context is canceled or timeout, the db transaction is leaked which cannot be commit or rollback in some extreme scenario. It may cause massive lock wait timeouts and high load on the underlying database.
The following describes the basic flow:
Goroutine 1
Call
(*DB) BeginTx
begins a transaction with a userContext. In(*DB)BeginTx
, a new goroutine(*Tx)awaitDone
which monitor context and rollback tx if needed will be created.Goroutine 2(awaitDone)
block on
tx.ctx.Done()
Goroutine 1
Execute some insert or update sqls on the database
Goroutine 1
Commit the transaction,
(*Tx)Commit
set the atomic variabletx.done
to 1.Goroutine 3(maybe global timer)
Cancel userContext which be passed to
Tx
Goroutine 1
(*Tx)Commit
checkstx.ctx.Done()
. Due to context has been canceled, it will returncontext.Canceled
orcontext.DeadlineExceeded
error immediately and abort the realCOMMIT
of transaction.Goroutine 2
Release with
tx.ctx.Done()
signal, execute(*Tx)rollback
. However the atomic variabletx.done
is 1 currently, it will returnErrTxDone
error immediately and abort the realROLLBACK
of transaction.What did you expect to see?
Rollback the transaction
What did you see instead?
The transaction hangs up and massive db lock wait timeouts
The text was updated successfully, but these errors were encountered: