Skip to content

fix(pg): settle a query once when a value fails to serialize - #3821

Open
YOGESH256 wants to merge 1 commit into
brianc:masterfrom
YOGESH256:fix/bind-error-settle-once
Open

YOGESH256 wants to merge 1 commit into
brianc:masterfrom
YOGESH256:fix/bind-error-settle-once

Conversation

@YOGESH256

Copy link
Copy Markdown

Fixes #3820.

When a parameter fails to serialize (a toPostgres() that throws, a BigInt in a JSON value), the catch block in Query.prepare sends Close + Sync (added in #3574 so the connection does not wedge) and then calls handleError immediately. The query is still the client's active query, so the ReadyForQuery that answers the Sync also runs handleReadyForQuery: the callback fires a second time with (null, result) and no rows, and a Query object emits end after error.

This hands the error to the ReadyForQuery handler through _canceledDueToError, the same path a throwing type parser uses, so the query settles once.

Tests:

  • throw-in-bind-tests.js: the stubbed sync now answers with readyForQuery like the server does, plus three new cases (callback runs once, no end after error, the next query runs). The "runs once" cases fail on master.
  • new bind-error-settles-once-tests.js integration test against a real server, pipeline on and off.

Ran make test-unit (290 pass) and the integration suite locally on PostgreSQL 17.5; only ssl-tests.js fails here because the local server has no SSL.

No behaviour change for the promise API. For a Query object with no error listener the throw now surfaces from the ReadyForQuery handler instead of synchronously out of client.query(), which is where a type-parser failure already surfaces it.

Since brianc#3574 the bind catch block sends Close + Sync and then reports the
error right away. The query is still the active one, so the ReadyForQuery
that answers the Sync runs the success path too: the callback fires a
second time with no rows, and a Query object emits 'end' after 'error'.

Hand the error to the ReadyForQuery handler through _canceledDueToError
instead, the way a failing type parser already does, so the query settles
exactly once.

Fixes brianc#3820
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.

Query settles twice when a parameter fails to serialize (callback gets error, then success with no rows)

1 participant