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

catch panic within transaction to complete rollback (fixes #748) #775

Merged
merged 2 commits into from
Sep 24, 2022

Conversation

sio4
Copy link
Member

@sio4 sio4 commented Sep 22, 2022

Connection.Transaction() starts a transaction before executing a given inner function and then commits or rollback the transaction controlled by the return error value of the inner function. However, as reported in #748, it just exits without committing or rolling back the current transaction so the transaction (and lock status) could remain as open (it could depend on the behavior of the backing database engine).

The current behavior of the method is:

=== RUN   Test_Connection_Transaction
[POP] 2022/09/22 20:08:51 sql - --- BEGIN Transaction ---
--- FAIL: Test_Connection_Transaction (0.00s)
panic: handler panic [recovered]
	panic: handler panic
<...>

The fixed behavior by this PR is:

=== RUN   Test_Connection_Transaction
[POP] 2022/09/22 20:11:01 sql - --- BEGIN Transaction ---
[POP] 2022/09/22 20:11:01 sql - --- ROLLBACK Transaction (inner function panic) 

Additionally, this PR added log(logging.SQL,...) for begin, commit, and rollback actions so the transaction status could be easily observed along with SQL statements when the user enabled SQL logging.

fixes #748

@sio4 sio4 added bug Something isn't working security labels Sep 22, 2022
@sio4 sio4 added this to the v6.0.7 milestone Sep 22, 2022
@sio4 sio4 self-assigned this Sep 22, 2022
@sio4 sio4 mentioned this pull request Sep 22, 2022
30 tasks
@sio4 sio4 requested review from a team September 22, 2022 12:15
Copy link
Member Author

@sio4 sio4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment on the code

connection.go Show resolved Hide resolved
connection.go Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working s: fixed was fixed or solution offered
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pop.Connection.Transaction can leak connections
1 participant