Repository navigation
fix(pg): mark client not queryable when a FATAL ends the session - #3836
Open
princejain756 wants to merge 1 commit into
Open
princejain756 wants to merge 1 commit into
princejain756 wants to merge 1 commit into
Conversation
An ErrorResponse with severity FATAL (pg_terminate_backend, restart, failover) terminates the session, but the client stayed queryable. A pool user that handles the query error and calls release() returned the dead client to the idle list, and the next connect() handed it out again. Mark the client not queryable before reporting the error so release() inside the error callback sees the dead client and the pool destroys it instead of reusing it. Fixes brianc#3826
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.
Fixes #3826
When the server ends a session mid-query with a FATAL ErrorResponse (
57P01frompg_terminate_backend, a restart, or a failover), the error goes to the active query and the client stays_queryable. A pool user that handles the query error and callsrelease()returns the client to the idle list, so the nextpool.connect()hands out a client whose session no longer exists. The reporter's repro showsthe same client again: trueand the next query failing with "Connection terminated unexpectedly".The client now marks itself not queryable before reporting the error. The flag is set before
handleErrorbecause the repro'srelease()runs inside the query error callback, andpg-pool's_releasealready destroys clients with_queryable === false.Validation: new unit tests cover both directions:
_queryable === falseafter a FATAL during an active query, and unchanged for a regular ERROR. The FATAL test fails against the old code.make test-unitpasses 290 tests and eslint is clean.