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

Check for bad connections #1256

Closed
jethrogb opened this Issue Oct 11, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@jethrogb
Contributor

jethrogb commented Oct 11, 2017

There is currently no portable way to tell whether a database connection is still usable. Yes, queries might return an Error, but you can't easily tell from that whether it was just something with the query or database, or the connection. Also, when using connection pooling, you want to know when a connection is returned to the pool whether to retire it or not. This would require just querying the connection without knowing anything about its history.

I suggest adding an fn is_usable to trait Connection or similar. In Postgres, this can be implemented with PQstatus. MySQL hopefully has something similar.

@sgrif

This comment has been minimized.

Member

sgrif commented Oct 11, 2017

You can easily test this with connection.execute("SELECT 1").is_ok(). I don't think we need an explicit method for this.

@sgrif sgrif closed this Oct 11, 2017

@jethrogb

This comment has been minimized.

Contributor

jethrogb commented Oct 11, 2017

That requires a network round-trip to complete. For the connection pooling use, that basically means every query now takes twice as long.

Also, that still doesn't let you distinguish between network errors and other random DB server errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment