Conversation
When a query throws while it is built (an undefined value, more than
65534 parameters, a serializer that throws), `execute` has already queued
it to await an answer, but nothing of it was written. The catch then
rejected the connection's current query with the new query's error and
left the failed query waiting for an answer that never comes, so every
later answer on the connection went to the wrong query:
await sql`select 1`
const a = sql`select pg_sleep(0.1), 1 as x`
, b = sql`select ${ undefined }`
, c = sql`select 3 as x`
// a rejects with UNDEFINED_VALUE, b with "Cannot set properties of
// null (setting 'columns')", c never settles, nor does any later query
This is also why `sql.begin(sql => [sql`select 1`, sql`select ${ undefined }`])`
never settles (porsager#1082). On a reserved connection with the transaction
pipelined (`begin`, insert, failing query, insert, `commit`), both inserts
committed.
Send a query the server is sure to refuse in the failed query's place.
The failed query then gets an answer of its own, every later answer stays
with its query, and a transaction it was part of is aborted rather than
committed without it. The failed query is rejected with its own error, as
a retried query already is. It is no longer marked to be described first
or as a cursor, since either would make the server's error send a Sync of
its own and shift the next answer.
Fixes porsager#1082
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Author
|
I made a few PRs from Claude which fix some problems I was having. Can you take a look? |
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 query throws while it is built (an undefined value, more than 65534 parameters, a serializer that throws),
executehas already queued it to await an answer, but nothing of it was written. The catch then rejected the connection's current query with the new query's error and left the failed query waiting for an answer that never comes, so every later answer on the connection went to the wrong query:This is also why
sql.begin(sql => [sqlselect 1, sqlselect ${ undefined }])never settles (#1082). On a reserved connection with the transaction pipelined (begin, insert, failing query, insert,commit), both inserts committed.Send a query the server is sure to refuse in the failed query's place. The failed query then gets an answer of its own, every later answer stays with its query, and a transaction it was part of is aborted rather than committed without it. The failed query is rejected with its own error, as a retried query already is. It is no longer marked to be described first or as a cursor, since either would make the server's error send a Sync of its own and shift the next answer.
Fixes #1082