- Notifications
You must be signed in to change notification settings - Fork515
improve is_closed effectiveness#1229
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
paolobarbolini merged 3 commits intorust-postgres:masterfromneondatabase:fix-connection-closureOct 5, 2025
Merged
improve is_closed effectiveness#1229
paolobarbolini merged 3 commits intorust-postgres:masterfromneondatabase:fix-connection-closureOct 5, 2025
+69 −8
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
self.connection.block_on(self.client.batch_execute(query)) | ||
} | ||
/// Check the connection is alive and wait for the confirmation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Suggested change
/// Check the connection is alive and wait for the confirmation. | |
/// Checkthatthe connection is alive and wait for the confirmation. |
simple_query::batch_execute(self.inner(), query).await | ||
} | ||
/// Check the connection is alive and wait for the confirmation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Suggested change
/// Check the connection is alive and wait for the confirmation. | |
/// Checkthatthe connection is alive and wait for the confirmation. |
paolobarbolini approved these changesOct 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks for the PR!
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
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.
Hi. We noticed that
is_closed()
is not always super effective, especially in thepostgres
crate. I've added a couple utilities to try and improve this state.Problem 1:
is_closed()
checks if the channel is closed, not if the connection is closed. These can be the same, but currently the channel is only closed whenConnection
is dropped. Inpostgres::Client
,Connection
never gets dropped. Fix is to force close the receiver on terminal state.Problem 2: The connection will only turn if something happens. Sometimes closure can be silent, so even still it seems open. You only can check it's valid if you try to run a query or if the TCP keepalive triggers. Running a
SELECT 1;
is a common workaround, but in my understanding, a singleSYNC
message is cheaper and doesn't cause any logging - so it's a better liveness check than running a full query.Thanks for your consideration