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
fix(postgres): invalidate connection after client-side timeout #15144
Conversation
The `query_timeout` feature of the `pg` package helps handle stuck TCP connections more quickly and gracefully by implementing a client-side timeout: brianc/node-postgres#1713 Sequelize started passing this dialect-specific option through to `pg` here: sequelize#13258 I believe we also want to invalidate the connection when a client-side timeout occurs. We shouldn't try to reuse the stuck connection because...it's stuck. This PR updates the error handling code so that the connection is invalidated if the error matches the one thrown from here: https://github.com/brianc/node-postgres/blob/5538df6b446f4b4f921947b460fe38acb897e579/packages/pg/lib/client.js#L529
@sincerekamal Since you added the pass-through for the |
Hi @harrykao |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we can make a test with a very low query_timeout
and a query that does take a while? Not a high priority but would be nice to see.
Apart from that I think this should not be an issue, but I do have a question about your explanation. See my comment about that
@WikiRik Thanks for the review. I've added a test. I'm not sure about coding style here and I'd be happy to do another round to make this more consistent with the rest of the code. |
Hrm, it looks to me like the native bindings don't pass https://github.com/brianc/node-pg-native/blob/master/index.js#L14 Or implement Would it make sense to skip these tests when testing against native? |
I think it would be fine to skip these on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small suggestion, but it's non blocking
I think it's fine having the new test functions here, especially since a developer might not directly expect that getConnectionPid
also releases the connection.
Co-authored-by: Rik Smale <13023439+WikiRik@users.noreply.github.com>
Thanks @WikiRik! |
@WikiRik Could I get a v6 release with this fix? |
Can you open a new PR with this change towards our v6 branch? |
Pull Request Checklist
Description Of Change
The
query_timeout
feature of thepg
package helps handle stuck TCP connections more quickly and gracefully by implementing a client-side timeout:brianc/node-postgres#1713
Sequelize started passing this dialect-specific option through to
pg
here:#13258
I believe we also want to invalidate the connection when a client-side timeout occurs. We shouldn't try to reuse the stuck connection because...it's stuck.
This PR updates the error handling code so that the connection is invalidated if the error matches the one thrown from here:
https://github.com/brianc/node-postgres/blob/5538df6b446f4b4f921947b460fe38acb897e579/packages/pg/lib/client.js#L529