-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: evict connections with open transactions on pool release #3597
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
base: master
Are you sure you want to change the base?
Conversation
| } | ||
| const activeQuery = this._getActiveQuery() | ||
| this._activeQuery = null | ||
| this._txStatus = msg?.status ?? null |
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.
Is this check just for tests and pg-native? Both should probably be updated to consistently report a status in their readyForQuery events.
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.
Added integration tests and updated PR description. However pg-native is not supported because this is a protocol level feature.
|
@charmander thanks for the review. I added a log to align with the behavior in other cases. I couldn’t find a clean way to surface an error at that point since Do you think this behavior change should be behind a pool option and disabled by default? |
Though I think how the pool behaves now (doesn't have any concept of the client being in a transaction and will happily rent it out to another caller later) is almost always wrong, I think it risks weird behavioral breaking changes if we change the default behavior in the So for pg@8.x it would be To opt into the behavior. Then in 9.x we can make this behavior the default & actually remove the feature flag entirely since I don't see any reason to allow the old, invalid behavior long term.
I agree w/ @panga that |
Summary
Behavior Changes
Problem
When a client with an active transaction (BEGIN without COMMIT/ROLLBACK) is released back to the pool, the connection is returned in a non-idle transaction state. The next consumer that checks out this connection inherits the open transaction, which can cause:
This is a known as "leaked/poison connection" problem in connection pools. This feature was recently added in Go pgx jackc/pgx#2481
Notes
pg-nativebecause it works at protocol level which we don't have access inlibpq.