Repository navigation
fix(pg-cursor): handle exceptions from row type parsers - #3840
Open
IbrahimHafez1 wants to merge 3 commits into
Open
IbrahimHafez1 wants to merge 3 commits into
IbrahimHafez1 wants to merge 3 commits into
Conversation
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 #3839.
A custom row type parser can throw from pg-cursor's PostgreSQL message handler, escaping an awaited
read()and terminating the process. pg-query-stream inherits the same failure. Coreclient.query()already rejects this kind of parser error normally.Catch the parser exception and stop parsing further rows in that batch. Close the portal at the suspended/final batch boundary and report the error once after protocol completion. Pending/subsequent reads receive the error; the client remains usable. Preserve the first parser error if a later row also produces a server error. Shared error dispatch clears the active callback before invoking it and reports only once, including when a query timeout precedes protocol completion.
Nine new regression cases cover object/array rows, suspended/final batches, queued reads, callback and promise consumers, async iteration and flowing streams, one error/close notification, portal release, a queued subsequent query, and timeout completion without duplicate error delivery.
Validation on Node 22.23.4 and PostgreSQL 16.15:
ca68aec.There is no new SQL or successful-row allocation. Error containment adds a guard and try/catch to the existing parse operation. Local warmed 100k-row microbenchmarks varied between runs (6.34→6.64ms and 7.25→5.31ms); these do not establish a reliable speedup or end-to-end performance guarantee.
Current code and related open/closed reports were checked. The timeout, close, concurrent-read and core-query proposals mentioned in the issue address different paths. Exceptions thrown by application event listeners are outside this change.
AI assistance was used for investigation, implementation and review.