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

Correctness fix for Handle #2541

Merged
merged 1 commit into from Nov 20, 2023
Merged

Correctness fix for Handle #2541

merged 1 commit into from Nov 20, 2023

Conversation

hgschmie
Copy link
Contributor

There is a really obscure (and usually already fatal) error condition
where during handle creation, the connection object becomes no longer
viable (e.g. the database crashes, the connection gets closed). In that
case, either transactionHandler.specialize() or
transactionHandler.isInTransaction() will throw a SQLException (or a
runtime exception) and the cleanup handler for the connection is never
added. Technically, the handle will there leak the connection (which is
already non-viable because it caused the exception in the first
place). This fix moves the cleanup before calling the methods which will
ensure that the connection will be cleaned up in every situation.

This may change user visible behavior slightly; instead of a
SQLException, it is possible that now a ConnectionException with the
root exception attached is now observed. This is unlikely but possible.

There is a really obscure (and usually already fatal) error condition
where during handle creation, the connection object becomes no longer
viable (e.g. the database crashes, the connection gets closed). In that
case, either `transactionHandler.specialize()` or
`transactionHandler.isInTransaction()` will throw a SQLException (or a
runtime exception) and the cleanup handler for the connection is never
added. Technically, the handle will there leak the connection (which is
already non-viable because it caused the exception in the first
place). This fix moves the cleanup before calling the methods which will
ensure that the connection will be cleaned up in every situation.

This may change user visible behavior slightly; instead of a
SQLException, it is possible that now a `ConnectionException` with the
root exception attached is now observed. This is unlikely but possible.
Copy link

sonarcloud bot commented Nov 20, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@hgschmie hgschmie merged commit f48664c into jdbi:master Nov 20, 2023
44 checks passed
@hgschmie hgschmie deleted the handle-fix branch November 20, 2023 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants