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

Add connection check to Trilogy #154

Merged
merged 1 commit into from
Feb 5, 2024
Merged

Add connection check to Trilogy #154

merged 1 commit into from
Feb 5, 2024

Conversation

jhawthorn
Copy link
Member

@jhawthorn jhawthorn commented Jan 29, 2024

Same as #134 but with requested Ruby API change: always raises an exception on error, and name is #check.

This adds a very cheap connection check to Trilogy. This cheap check can be used before a connection for example is checked out from a connection pool.

It allows for making the client more robust in the case of the server having disconnected (like a failover, an intermediate proxy like ProxySQL or VTGate restarted etc) but it can be reconnected safely.

It works by doing a non-blocking recv to peek if there's any data. If there is, or if the function would otherwise block it means the connection is still safe.

If the TCP connection has been closed, recv immediately returns with zero bytes read. This indicates the connection is no longer safe to use. We do this directly on the file descriptor to be consistent regardless of things like TLS being used.

This adds a very cheap connection check to Trilogy. This cheap check can
be used before a connection for example is checked out from a connection
pool.

It allows for making the client more robust in the case of the server
having disconnected (like a failover, an intermediate proxy like
ProxySQL or VTGate restarted etc) but it can be reconnected safely.

It works by doing a non-blocking `recv` to peek if there's any data. If
there is, or if the function would otherwise block it means the
connection is still safe.

If the TCP connection has been closed, `recv` immediately returns with
zero bytes read. This indicates the connection is no longer safe to use.
We do this directly on the file descriptor to be consistent regardless
of things like TLS being used.

Co-authored-by: Daniel Colson <composerinteralia@github.com>
Co-authored-by: John Hawthorn <john@hawthorn.email>
@jhawthorn jhawthorn merged commit 7457262 into main Feb 5, 2024
14 checks passed
@jhawthorn jhawthorn deleted the add-connection-check2 branch February 5, 2024 19:08
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