Fix OperationalError not caught during reconnect on dead connections#9
Open
terezbw wants to merge 2 commits into
Open
Fix OperationalError not caught during reconnect on dead connections#9terezbw wants to merge 2 commits into
terezbw wants to merge 2 commits into
Conversation
|
Maksim Kozin seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
02882f9 to
45c237f
Compare
…ailures
Previously create_cursor() caught only InterfaceError. When a persistent
connection is closed server-side (e.g. during gunicorn worker recycling),
the first cursor attempt raises InterfaceError and triggers reconnect().
If the subsequent connect() call itself raises OperationalError, the
exception escaped unhandled, causing a 500 response to the client.
Changes:
- create_cursor() now catches both InterfaceError and OperationalError
- if reconnect() raises OperationalError, one additional attempt is made
via ensure_connection() before giving up
- added tests for both new paths
deb0ba4 to
97553ee
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



When a gunicorn worker is recycled, all its persistent PG connections are closed server-side. On the next request, create_cursor() catches InterfaceError and calls reconnect(). If the reconnect's connect() call itself fails (e.g. transient TCP timeout), the resulting OperationalError was not caught and propagated as a 500.
Two changes: