-
Notifications
You must be signed in to change notification settings - Fork 886
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
Pool methods override context #1287
Comments
There was a small change in how context cancellation is handled in pgxpool in v4.17.0. But its not obvious how that change would have caused this. I don't have docker on my machine, so I can't run your example the exact same way you do. It works when running on MacOS and simply stopping the local database server. ... Was finally able to duplicate it by connecting to a remote server severing the network connection with a firewall rule. ... Okay, I think I have figured it out. @jameshartig It looks like this was broken by #1259 / 91c9e84. Establishing a connection is no longer affected by context, but that means that Looked at it for a while but did not see any simple fix. |
@jackc this might need to be fixed in puddle. Ideally it could create the resource in a goroutine and select against the ctx.Done. Also, with your latest changes it shouldn't hang forever. It should only hang until the connect timeout or 20 seconds, right? |
@jackc created an MR for puddle here: jackc/puddle#21 |
Fix is in release v4.17.1. |
I confirm it works Thank you |
Describe the bug
Context cancelled does cancel Ping (maybe others methods?) operation systematically.
It does 1 time. But then the
Ping
call hangs.To Reproduce
You initially connect to a DB to achieve a connection. Then you simulate a problem with the connection by shutting (pausing) de DB image.
Expected behavior
Ping should not hang. Here, it overrides the context cancellation.
Actual behavior
Once the DB shuts down, the Ping returns an error (timed-out). Then it hangs.
Version
$ go version
:go version go1.18.3 darwin/amd64
$ grep 'github.com/jackc/pgx/v[0-9]' go.mod
-> v4.17.0Additional context
v4.16.1 was acting the expected way. v4.17.0 introduces this different behavior.
I use this ping tips to check the connection status to a database after a query error in order to handle load-balancing over replicas, and error management.
Therefore, when I collect the query error correctly (as indicated above, the first Ping without DB returns an error), but the
Ping
to check the DB hangs forever (until the database reconnects at least). But as I lose the hand, I cannot update the database status.The text was updated successfully, but these errors were encountered: