fix(prefork): propagate cancel_running_job to running children (#82)#141
Merged
Conversation
In-process pools (native-async, classic async) implement notify_cancel as a no-op, so installing them on `self.dispatcher` is unnecessary — and breaks shutdown when native-async is enabled, because the parent thread keeps an `Arc<PyObject>` alive (async executor → PyResultSender → result channel sender), preventing the drain loop's `recv` from observing disconnection until the 30s drain timeout. Restore the original "dispatcher lives only inside the runtime task" ownership for in-process pools.
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
queue.cancel_running_job(job_id)now stops a cooperatively-checking task running in a prefork child within ~100 ms instead of being ignored until the task completes naturally.WorkerDispatcher::notify_cancel(default no-op) → bounded crossbeam channel → cancel-router thread inPreforkPool→ in-bandCancel { job_id }IPC message → child-side stdin reader thread → local cancel set consulted bycurrent_job.check_cancelled()via a registered hook.SIGUSR1or signal-handling — pure stdio pipes, so behaviour is identical on Linux, macOS, and (when prefork is supported) Windows.Storage::request_cancel) is still set, so pending-job cancel and the existing thread-pool path are unchanged.Closes #82.
Test plan
cargo check --workspace(default +postgres+redis+native-async)cargo clippy --workspace --all-targets -- -D warningscargo test --workspaceuv run python -m pytest tests/python/(498 passed, 9 skipped)test_prefork_cancel_running_job_stops_quicklyandtest_prefork_cancel_does_not_kill_childexercise the full end-to-end pathuv run ruff check py_src/ tests/uv run mypy py_src/taskito/ --no-incremental