Skip to content
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

database/sql: "rollback due to context cancellation" error consistency #28077

Closed
nvartolomei opened this issue Oct 8, 2018 · 2 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@nvartolomei
Copy link

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 remove runtime.Gosched() call from playground code on line 20, you'll get expected context canceled error.

go tx.awaitDone()

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.

@nvartolomei nvartolomei changed the title database/sql: rollback due to context cancellation error consistency database/sql: "rollback due to context cancellation" error consistency Oct 8, 2018
@kardianos
Copy link
Contributor

I think this is a duplicate issue. But either way I will look at it.

@kardianos kardianos self-assigned this Oct 9, 2018
@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 23, 2018
@bcmills bcmills added this to the Go1.12 milestone Oct 23, 2018
@kardianos
Copy link
Contributor

This is a duplicate of #25829 .

@golang golang locked and limited conversation to collaborators Oct 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants