fix(pg): keep a named statement usable after its values fail to serialize - #3797
Open
maxymlyskov wants to merge 1 commit into
Open
maxymlyskov wants to merge 1 commit into
maxymlyskov wants to merge 1 commit into
Conversation
…lize When a value's toPostgres() throws, or JSON.stringify meets a circular object, the catch around bind() sends a Close for the statement and a Sync. For a named statement the Close removes it from the server, but the client still lists it in parsedStatements: on first use the ParseComplete for the Parse already sent arrives after the catch and records the name, and on a later use the entry is already there. Every later query with that name skips Parse and fails with 26000 prepared statement "<name>" does not exist for the life of the connection, and so does a query with the same name pipelined behind the failing one. Only close the unnamed statement. A named statement that parsed stays prepared and matches the client's cache, so the next run binds to it as it would after any other error.
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.
When a value's
toPostgres()throws in a namedclient.query(), every later run of that name fails withprepared statement "<name>" does not exist. The catch aroundbind()sends Close, so the server drops the statement, but the name stays inparsedStatementsandhasBeenParsedskips Parse. On first use the lateParseCompleteputs it there.The catch now closes only the unnamed statement, so a named one stays prepared.
The added tests cover a first use, an already prepared name and a same-name query pipelined behind the failing one. They fail on master and pass here.
The same three cases (A, B, C) from a script against Postgres 16: