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