Skip to content

fix(pg): settle a query once when bind serialization throws - #3835

Open
princejain756 wants to merge 1 commit into
brianc:masterfrom
princejain756:fix-bind-throw-double-settle
Open

princejain756 wants to merge 1 commit into
brianc:masterfrom
princejain756:fix-bind-throw-double-settle

Conversation

@princejain756

Copy link
Copy Markdown

Fixes #3820

Since 8.22.0 a query whose parameter fails to serialize (a throwing toPostgres(), a BigInt in a JSON value, a circular object) settles twice: once with the error, then again as a success with zero rows.

connection.bind() throws before any bind message reaches the wire, and the catch in Query#prepare reported the error through the callback right away. The query stayed active, so when the server answered the follow-up sync with ReadyForQuery, handleReadyForQuery settled the same query again with (null, results).

The error now goes through the existing _canceledDueToError channel, so handleReadyForQuery reports it exactly once when the server responds, and no success settlement can follow.

Validation: added a "settles the query exactly once" unit test that fails on the old code (callback invoked twice) and passes now; the three existing bind-throw tests were updated to emit the readyForQuery a real server sends in reply to sync. make test-unit passes 288 tests and eslint is clean.

When a parameter fails to serialize, connection.bind() throws before any bind message reaches the wire. The catch reported the error through the callback immediately, but the query stayed active, so the server's ReadyForQuery answer to our sync settled the same query a second time as a success with zero rows.

Defer the error through the existing _canceledDueToError channel so handleReadyForQuery reports it 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