Skip to content

Parallel kill on session quit - #368

Closed
lionel- wants to merge 3 commits into
mainfrom
quit-kill-parallel
Closed

lionel- wants to merge 3 commits into
mainfrom
quit-kill-parallel

Conversation

@lionel-

@lionel- lionel- commented May 2, 2023

Copy link
Copy Markdown
Member

Branched from #367.

  • Split process cleanup into GC-specific finalisers and a global session-quit finaliser. The session finaliser collects all living processes and optionally their trees, and uses the new ps::ps_kill_parallel() to kill them in parallel with a grace delay controlled by cleanup_grace.

  • On creation, the cleanup info for the session finaliser is recorded in a doubly linked list that keeps track of living processes. It's doubly linked so that on GC of a process the node can be efficiently removed.

@lionel- lionel- changed the title Quit kill parallel Parallel kill on session quit May 2, 2023
Base automatically changed from kill-grace to main April 23, 2026 13:07
ps::ps_kill_parallel() was never released, so cleanup on GC and on
session quit failed. Use ps::ps_kill() for the process tree instead,
with the grace period converted to milliseconds.

Kill the process group of each process via processx's own handle,
as the old C finalizer did, so cleanup = TRUE kills the whole group
again and works without ps support. ps is only used for
cleanup_tree = TRUE, and only if ps supports the platform. Errors are
caught for each process, so one failure does not stop the others
from being cleaned up.

Only call into R from the C finalizer if cleanup = TRUE.

Replace the parallel cleanup test, which used an undefined helper,
with px-based tests for group kill, grace period and parallel kill
on session quit. Update C line numbers in error snapshots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gaborcsardi

Copy link
Copy Markdown
Member

I updated this to be current, but in the end I am not going to merge it. It is very hard to get this code right, it would only have real effect if we changed the default for the grace period to be non-zero, and that seems like a difficult change, considering that it would effect many packages that clean up subprocesses serially. I.e. it would potentially make those serial process cleanups much slower.

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.

2 participants