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: documentation of Tx.Commit() should notify driver developers to rollback if commit fails #33242
Comments
If a commit failed then the connection should be closed. This will cause the database to free any open transactions. |
@renthraysk No, the connection must stay open and it is. The transaction is closed. But transaction here is just some data on client side (like some data used for prepared statements). So the transaction closing doesn't send 'ROLLBACK;' command to the sql server. |
The For example, Those errors are usually hard to reproduce and to test with a real database (some db mocks would help driver developers of course, and tests with mocks should be written). The requirement for |
@renthraysk Sorry I missread your reply (just missed should). There are plenty of code samples where
With this code it is not possible for callers to distinguish was it an error from To workaround this case with buggy driver we can only do everything ourselves without
But it is preffered to not have such bugs in any of sql drivers. |
If a commit fails, the transaction is (or will be) rolled back. Drivers are not buggy. Better off with a func like this to deal with transactions...
|
@renthraysk Thanks for Your time. I wish to notice a small difference in using of a "commit" term. Actually this is database dependent issue. For example, PostgreSQL differs from Oracle documentation |
@renthraysk Small note about bugs in driver implementations. The SQLite database allows only 1 open transaction at time. So it is very sensitive for mentioned problem. Lets look what will be executed when
Two drivers do rollback on commit errors, two others don't. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
read https://golang.org/pkg/database/sql/#Tx.Commit
What did you expect to see?
A note for sql database driver developers about the case
when database commit fails then driver's commit implementation should try to rollback database transaction to free database transaction resources.
This rollback is required to be implemented in driver as
Tx.Commit()
always closes transaction.What did you see instead?
Commit commits the transaction.
The text was updated successfully, but these errors were encountered: