fix(rest): make async import-job cancellation actually stop the worker (#2824)#3069
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📓 Docs Drift CheckThis PR changes 1 package(s): 7 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
#2824) On a synchronous storage driver (better-sqlite3 / wasm fallback) every await in the import row loop resolves as a microtask, so a 50k-row import starved the Node event loop for minutes: the cancel route's HTTP handler (and every progress poll) never ran, the in-memory flag `shouldCancel` polls was never set, and the job finished `succeeded` with all rows written despite the user's cancel. - runImport now yields one macrotask at every progress boundary so pending I/O (cancel requests, progress polls) is serviced mid-import. - The worker's shouldCancel also reads the durable job row as a fallback, covering cancels accepted by another process or after a restart. - A late cancel wins the terminal state: the worker's final patch no longer overwrites the durable 'cancelled' with 'succeeded', and a job cancelled while still pending doesn't start at all. Co-Authored-By: Claude <noreply@anthropic.com>
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.
Summary
Fixes #2824 — cancelling a running async CSV import had no effect: the job kept writing all rows and finished
succeeded.Root cause: with a synchronous storage driver (better-sqlite3 / wasm fallback), every
awaitin the import row loop resolves as a microtask, so a 50k-row import monopolizes the Node event loop for its whole duration. The cancel route's HTTP handler (and every progress poll) never gets to run, so the in-memory flag thatshouldCancelpolls is never set.Three-part fix:
runImportyields one macrotask (setImmediate) at every progress boundary (everyprogressEveryrows), so pending I/O — the cancel request, progress polls — gets serviced during a large import. Root-cause fix; also unblocks live progress for the wizard.shouldCancelfalls back to reading the durable job row: a cancel accepted by another process (or after a restart dropped the in-memory flag) still stops the worker.cancelledwithsucceeded, and a job cancelled while stillpendingdoesn't start at all.Testing
import-runner-cancel.test.ts): mid-loop cancel stops at the next checkpoint with truthful counts; no-cancel path unaffected; yield happens even withoutshouldCancel.import-job-integration.test.ts): mid-flight cancel via the route; out-of-band durable cancel (no in-memory flag); late-cancel terminal-state guard.@objectstack/restsuite green (288 tests), build + DTS clean.cancelledat 17600/50000, row count stable afterwards), and an uncancelled control import still succeeds 50000/50000.Known remaining (out of scope): the wizard shows 「已导入 0 条」 after cancel instead of the actual partial count — objectui frontend issue (objectui#2393).
Co-Authored-By: Claude noreply@anthropic.com