Fast local connection checks like in go-sql-driver/mysql #2573
murfffi
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
TLDR Check out this implementation of the OptionResetSession pgx hook: https://github.com/murfffi/conncheck/blob/main/examples/sql.go#L27
If you use the database/sql API, pgx doesn't validate that a connection is open when it is taken from the pool - unlike other Go DB drivers like go-sql-driver/mysql . Instead, pgx provides the OptionResetSession pgx hook . Including the connection checks by default to pgx was rejected in 2021 and the hook was added. At the time, the connection checks worked only on Linux and only for non-TLS connections.
While working on another Go DB driver, I researched and implemented the checks for Windows, Linux and MacOS, both TLS and plain connections. I extracted it as library - https://github.com/murfffi/conncheck - and prepared that example for hooking it into pgx stdlib. I still don't think this will be accepted in pgx by default but I believe it can be useful to anybody who uses the stdlib implementation or the pgx.Pool .
All reactions