Skip to content

sqlite: roll back applyChangeset() when filter throws - #67947

Open
Ultranmus wants to merge 1 commit into
nodejs:mainfrom
Ultranmus:sqlite-filter-rollback
Open

Ultranmus wants to merge 1 commit into
nodejs:mainfrom
Ultranmus:sqlite-filter-rollback

Conversation

@Ultranmus

@Ultranmus Ultranmus commented Dec 1, 2026 •

Copy link
Copy Markdown

When the filter callback of database.applyChangeset() throws, the call throws but the tables accepted before the exception stay applied. An exception from onConflict rolls everything back, because xConflict returns SQLITE_CHANGESET_ABORT. xFilter has no way to abort: returning false only skips the table, so sqlite3changeset_apply() finishes with SQLITE_OK for the tables it already applied.

This wraps the apply in a savepoint when a filter is given, and rolls back to it when the filter threw. A savepoint is used rather than a transaction so that, when the caller already has a transaction open, the earlier writes in it are kept and the transaction stays usable (the case raised in #67841 (comment)). The cleanup follows the same RELEASE / ROLLBACK TO + RELEASE sequence that sqlite3changeset_apply() uses for its own savepoint. Calls without a filter are unchanged.

Tests cover the issue's repro, the open-outer-transaction case, and a non-throwing filter inside a transaction (to check that releasing the savepoint does not commit the outer transaction). The docs now describe what happens when filter throws.

The v22.x abort (FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal) is a separate issue: #60028 was not backported there. This PR does not address it.

Tested on macOS arm64 (release build of main + this commit): make test-sqlite and tools/test.py "test/parallel/test-sqlite*" pass. The issue's repro, plus the outer-transaction case:

v24.12.0 (unpatched) this branch
issue repro a: 1, b: 0 a: 0, b: 0
outer txn a: 1, b: 0, marker: 1 a: 0, b: 0, marker: 1, txn still open

AI use: Used AI tool for comment writing, PR description and assistance in testing

Fixes: #67841

When the filter callback of applyChangeset() throws, xFilter can only
tell SQLite to skip the remaining tables, so sqlite3changeset_apply()
returns SQLITE_OK and the tables accepted before the exception stay
applied. An exception from onConflict, by contrast, aborts and rolls
back the whole apply.

Wrap the apply in a savepoint when a filter is given and roll back to
it when the filter threw. A savepoint is used instead of a transaction
so that a transaction the caller already has open, and the writes made
in it before the call, are kept.

Fixes: nodejs#67841
Signed-off-by: Ultranmus <hashmack007@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/sqlite

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem. labels Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

Caution

AgentScan found account activity patterns that may be consistent with automation. This is a heuristic, not proof that this pull request was opened by an agent or violates policy. AI-assisted contributions are permitted, but automated tooling must not open pull requests without advance approval, and contributors must personally understand, test, verify, and take responsibility for every submitted change. See the AgentScan analysis, AI use policy, and automation policy for additional context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agentscan:automated-account c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sqlite: applyChangeset() keeps part of the changeset when the filter callback throws

2 participants