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

improve is_closed effectiveness #1229

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

conradludgate
Copy link

Hi. We noticed that is_closed() is not always super effective, especially in the postgres 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 when Connection is dropped. In postgres::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 single SYNC 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

@@ -487,6 +487,11 @@ impl Client {
self.connection.block_on(self.client.batch_execute(query))
}

/// Check the connection is alive and wait for the confirmation.

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.
/// Check that the connection is alive and wait for the confirmation.

@@ -531,6 +531,12 @@ impl Client {
simple_query::batch_execute(self.inner(), query).await
}

/// Check the connection is alive and wait for the confirmation.

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.
/// Check that the connection is alive and wait for the confirmation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants