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: Documentation clarification regarding Tx #28474

Open
pjebs opened this issue Oct 29, 2018 · 2 comments
Open

database/sql: Documentation clarification regarding Tx #28474

pjebs opened this issue Oct 29, 2018 · 2 comments
Labels
Documentation help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@pjebs
Copy link
Contributor

pjebs commented Oct 29, 2018

The docs state:

Tx is an in-progress database transaction.

A transaction must end with a call to Commit or Rollback.

After a call to Commit or Rollback, all operations on the transaction fail with ErrTxDone.

The statements prepared for a transaction by calling the transaction's Prepare or Stmt methods are closed by the call to Commit or Rollback.

The documentation should clarify if that is only the case if Commit or Rollback return a nil error.
What happens if they return a non-nil error? Should we try and call Commit or Rollback again? Will other operations still return ErrTxDone?

@ianlancetaylor
Copy link
Contributor

CC @kardianos

@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 29, 2018
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Oct 29, 2018
@kardianos
Copy link
Contributor

I think that depends on the error it returns. What you are asking is undefined at this level. Maybe the Tx Commit failed because of a temporary network condition. But the safest way is to assume a rollback on error.

In most cases on the server, an open Tx on the DB Server (as far as I understand) will rollback the Tx (eventually). But even this may depend on the exact settings of the system and session. So to answer your question about what you should do? Assume the Commit (or rollback) will (evetually) result in a rollback (depending your server db and db and session settings) and rely the failure without an immediate retry of said operation.

That being said, We don't have a great state chart of what could go wrong, nor do we have a list documentation from various vendors on how their systems handle transaction failures, and what their failure modes are.

As a counter-point to the above, if you are running something like cockroachdb, it may fail with a specific error message that says "please retry, your tx was rolledbacked due to another tx activity".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants