Correctly ROLLBACK transaction when dropped during BEGIN.
#3980
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously if the transaction was dropped while the transaction was being set up it was possible that the transaction was successfully opened but not closed. In common usage this would result in returning an open transaction to the connection pool which would have unexpected effects ranging from errors due to trying to nest transaction or serious bugs such as intended changes not occurring as they were unexpectedly inside a transaction that would never commit.
This resolves the issue by constructing the
Transactionobject (which activates the drop handler) before starting to open the transaction. In the worst case this could result in trying toROLLBACKa transaction that was never started but this just results in a harmless error which is much better than leaving an unexpected open transaction active on the connection.Fixes: #3932
Is this a breaking change?
No. While the changed behaviour is observable it relies on exact future
polltiming and would almost certainly be undesirable to trigger intentionally.