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

Ensure that the connection is always closed #2458

Merged
merged 2 commits into from
Aug 9, 2023

Conversation

hgschmie
Copy link
Contributor

@hgschmie hgschmie commented Aug 8, 2023

Even if the init code in Jdbi or Handle fails, ensure that we don't leak connections.

Fixes #2446

stevenschlansker and others added 2 commits August 8, 2023 11:33
Right now, we check if a connection is closed before closing it. Also, if a plugin
fails to customize a Handle, the connection can leak

However, this isn't good enough: even if the server closed the connection,
we might have borrowed this from a pool, which needs to know we've returned it.

Connection.close is specified to no-op if called more than once, so it's safe to just do it regardless.

Fixes jdbi#2446
If the c'tor of a handle throws an exception, ensure that the underlying
connection is closed as the caller will not have a chance to do so with
try-with-resources

This fixes the cause of jdbi#2446
@sonarcloud
Copy link

sonarcloud bot commented Aug 8, 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 2 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@stevenschlansker
Copy link
Member

@kristoffSC, do you want to verify this proposed change fixes the connection leak for you?

@hgschmie hgschmie merged commit eeb3391 into jdbi:master Aug 9, 2023
36 checks passed
@hgschmie hgschmie deleted the fix-issue-2446 branch August 9, 2023 01:33
@kristoffSC
Copy link

@kristoffSC, do you want to verify this proposed change fixes the connection leak for you?

@hgschmie @stevenschlansker
I confirm that this PR fixes #2446

Is there any estimate date for new release?
Thanks.

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.

[Bug] Jdbi3-core - connection object can be stuck in a connection pool forever if connection was closed.
3 participants