Repository navigation
fix(pg): don't poison the statement cache when a named bind fails to serialize - #3868
Open
Cdineshreddy12 wants to merge 1 commit into
Open
Cdineshreddy12 wants to merge 1 commit into
Cdineshreddy12 wants to merge 1 commit into
Conversation
…serialize
When a parameter of a named prepared statement throws while being
serialized, the client sends Close('S', name) + Sync to clean the
statement up on the server. But the name stayed in the client's
parsed-statement cache: on first use the ParseComplete for the Parse that
was already sent recorded it, and on reuse of an already-parsed name it
was never removed. Either way the client then believed the statement
existed while the server had closed it, so every later query with that
name failed with 'prepared statement "name" does not exist' (SQLSTATE
26000).
The bind-serialization catch now drops the name from both statement
caches and flags the query so the trailing ParseComplete is not recorded.
Cdineshreddy12
force-pushed
the
fix/named-statement-cache-poisoning
branch
from
November 19, 2026 07:21
2624236 to
edd8bb2
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.
Fixes #3867
When a parameter of a named prepared statement fails to serialize, the catch in
Query.preparecloses the statement on the server (Close('S', name)+Sync, from #3574) but the client's statement cache was left pointing at it, so every later query reusing that name failed withprepared statement "<name>" does not exist. Full write-up and repro in the issue.Two cases, both fixed in the same catch:
Parsewas already sent, soParseCompletecomes back and_handleParseCompletewould record the name right after theCloseremoved it. A new_statementClosedDueToErrorflag on the query makes that handler skip the recording.Parseis sent, so the existing cache entry just needs removing, which the catch now does for bothparsedStatementsandsubmittedNamedStatements.Unnamed statements are unaffected (
if (this.name)guard), so the existing throw-in-bind tests are unchanged.Note on #3820 / #3835: this is a different bug on the same catch path (cache vs. double-settle), and #3835 keeps sending
Close+Sync, so this poisoning is still present with that PR applied. The two fixes are independent; whichever lands first, I'll rebase this onto it — the only shared line is thehandleError/defer call, which I left untouched here.Added an integration test in
query-error-handling-prepared-statement-tests.js(uses the promise API so it settles once regardless of #3820); it fails on master with "prepared statement does not exist" and passes with this change. Ran it and the prepared-statement integration suite against PostgreSQL 18, and the client unit tests (the one pre-existingpassword-callback-tests.jsfailure is unrelated to this change).