Skip to content

fix(ext/node): run node:sqlite backup off the main thread - #36581

Open
Tango992 wants to merge 3 commits into
denoland:mainfrom
Tango992:fix-node-sqlite-backup
Open

fix(ext/node): run node:sqlite backup off the main thread#36581
Tango992 wants to merge 3 commits into
denoland:mainfrom
Tango992:fix-node-sqlite-backup

Conversation

@Tango992

Copy link
Copy Markdown
Contributor

backup() from node:sqlite returned a promise, but the copy was done entirely inside a synchronous op: the whole sqlite3_backup_step loop ran on the main thread before the promise settled, so the event loop was blocked for the duration of the backup and the rate/progress options had no practical effect on responsiveness.

Split the single op_node_database_backup op into an init/step/finish sequence backed by a BackupJob resource that owns the raw sqlite3_backup handle. Each sqlite3_backup_step now runs on the blocking threadpool via spawn_blocking and yields at the await point, mirroring Node's BackupJob/ThreadPoolWork. When no progress callback is given, op_node_database_backup_run drives the loop in Rust to avoid a JS round-trip per step, while still awaiting each step.

Changes in this PR were assisted using Claude

`backup()` from `node:sqlite` returned a promise, but the copy was done
entirely inside a synchronous op: the whole `sqlite3_backup_step` loop ran
on the main thread before the promise settled, so the event loop was blocked
for the duration of the backup and the `rate`/`progress` options had no
practical effect on responsiveness.

Split the single `op_node_database_backup` op into an init/step/finish
sequence backed by a `BackupJob` resource that owns the raw
`sqlite3_backup` handle. Each `sqlite3_backup_step` now runs on the blocking
threadpool via `spawn_blocking` and yields at the await point, mirroring
Node's `BackupJob`/`ThreadPoolWork`. When no `progress` callback is given,
`op_node_database_backup_run` drives the loop in Rust to avoid a JS
round-trip per step, while still awaiting each step.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant