You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Parser in @pgsql/parser (parser/templates/index.js.template, index.cjs.template) cached a rejected load forever: if the version import or loadModule() failed once, every later parse() rethrew the stale error and parser.ready never settled.
Now:
concurrent callers share one load attempt; the parser is only published after init succeeds
on failure the cached attempt is cleared and that attempt's ready rejects
the next call retries with a fresh ready promise
Regression tests in parser/test/esm.test.mjs cover both the ESM and CJS entry points using a PG 18 loader that fails once: concurrent callers and ready see the failure, parseSync() still reports unloaded, and the next parse() succeeds. Both tests fail on unmodified main. README documents the ready semantics.
Found by luxor-code-review on #201; kept separate from that PR.
Parser loading can be retried after a failed attempt, allowing later parsing to succeed without requiring a restart.
Concurrent parsing requests share the same loading attempt. The parser becomes available only after its optional initialization completes successfully.
Documentation
Clarified that retrying after a loading failure creates a new readiness promise.
No actionable comments were generated in the recent review.
Walkthrough
The parser templates update ready handling and load retries. They assign the imported module to this.parser only after its optional loadModule() completes. Tests cover retry behavior for ESM and CommonJS entry points.
Changes: Parser load retry lifecycle
Layer / File(s)
Summary
Ready promise and retry handling parser/templates/index.cjs.template, parser/templates/index.js.template, parser/test/esm.test.mjs, parser/README.md
Both parser templates reject ready when loading fails and allow a later attempt to create a new promise. Tests cover failed and successful retries for ESM and CommonJS. The README describes the replacement promise.
Module initialization before assignment parser/templates/index.cjs.template, parser/templates/index.js.template
Both templates call an available loadModule() before assigning the imported module to this.parser.
This change lets parser loading recover after a transient failure instead of caching the rejection. The retry behavior is covered for both ESM and CommonJS, and no merge-blocking risk was found.
Architecture risk: Low · up to add45
The change affects 1 system.
Changed systems:parser
Architecture concerns
No architecture-level concerns identified.
Review details
Systems and components
observed — parser (service) was modified; 4 changed files map to changed impact.
Before / after behavior
observed — Modified behavior in parser/README.md: The ready property description now says that after a loading failure, the next load attempt replaces its promise; the previous description only said it resolves when loading completes.
observed — Modified behavior in parser/templates/index.cjs.template: The constructor now initializes ready through _resetReady(). That method creates a promise with resolve and reject handlers and attaches a rejection handler; the previous promise could only resolve.
observed — Modified behavior in parser/templates/index.cjs.template: loadParser() now resets ready when there is no current reject handler and catches load failures to clear _loadPromise, reject the current ready, and rethrow the error. This replaces the prior shared load promise, which was not cleared on failure and did not reject ready.
observed — Modified behavior in parser/templates/index.cjs.template: _doLoad() now stores the required module locally, awaits its optional loadModule(), and assigns it to this.parser afterward. Previously it assigned the module before awaiting loadModule().
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title "fix(parser): retry failed parser loads" states the main change. The changeset makes failed parser loads retryable: a failed load clears the shared promise, rejects ready, and lets a later…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title "fix(parser): retry failed parser loads" states the main change. The changeset makes failed parser loads retryable: a failed load clears the shared promise, rejects ready, and lets a later call create a new ready promise. The title is specific, concise, and uses a conventional commit prefix.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Fix failing CI checks
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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
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.
Summary
Parserin@pgsql/parser(parser/templates/index.js.template,index.cjs.template) cached a rejected load forever: if the version import orloadModule()failed once, every laterparse()rethrew the stale error andparser.readynever settled.Now:
readyrejectsreadypromiseRegression tests in
parser/test/esm.test.mjscover both the ESM and CJS entry points using a PG 18 loader that fails once: concurrent callers andreadysee the failure,parseSync()still reports unloaded, and the nextparse()succeeds. Both tests fail on unmodifiedmain. README documents thereadysemantics.Found by luxor-code-review on #201; kept separate from that PR.
Implemented in session Fix cached failed load in @pgsql/parser
Review with Devin · Open in Devin Desktop
Summary by CodeRabbit