database/sql: "rollback due to context cancellation" error consistency #28077
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go1.11.1
What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
https://play.golang.org/p/Yom8SR66l08
What did you expect to see?
panic: context canceled
What did you see instead?
panic: sql: transaction has already been committed or rolled back
There is a "race condition" when context is cancelled and
database/sql
context watcher rollbacks the transaction before the programmer has a chance to do it. If you removeruntime.Gosched()
call from playground code on line 20, you'll get expected context canceled error.go/src/database/sql/sql.go
Line 1672 in 7c3b324
The problem is a usability one, when you see the
sql: transaction has already been committed or rolled back
error it is hard to track down wether it was because the tx was rolled back due to cancellation or there is a bug in the application calling commit/rollback multiple times.The text was updated successfully, but these errors were encountered: