Skip to content

fix(pg): keep the connection error as the cause of the "not queryable" error - #3853

Open
osama-akhter wants to merge 1 commit into
brianc:masterfrom
osama-akhter:fix/unqueryable-error-cause
Open

osama-akhter wants to merge 1 commit into
brianc:masterfrom
osama-akhter:fix/unqueryable-error-cause

Conversation

@osama-akhter

Copy link
Copy Markdown

When the server ends a connection with a FATAL error while no query is running, such as idle_in_transaction_session_timeout (25P03), the client emits that error as 'error' and marks itself not queryable. The next query fails with Client has encountered a connection error and is not queryable, a new error with no code and no link to the FATAL one. So code that sees only the query's error cannot tell an idle timeout from a dropped socket.

The fix keeps the first error that made the client unqueryable and attaches it as the standard cause of that error, in both the JS and the native client. It keeps the first one because the socket closing right after the FATAL raises a second, generic Connection terminated unexpectedly error. The message and the error type stay the same. On Node versions before 16.9 the cause option is ignored, so nothing changes there.

Client was closed and is not queryable is unchanged: it follows a call to end(), with no error behind it.

Tests:

  • an integration test sets a short idle_in_transaction_session_timeout, opens a transaction, waits for the server to end the connection, then runs a query: its error carries the 25P03 error as cause. It skips the native client, because libpq does not report a FATAL error while no query is running.
  • a unit test for the JS client and a test for the native client make each client unqueryable and check the cause.

All fail on master and pass here.

Closes #3852

🤖 Generated with Claude Code

…" error

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Carry the reason a client became unqueryable as the cause of "not queryable" errors

1 participant