Repository navigation
Prevent native child termination from signaling reused PIDs - #786
Merged
Merged
Conversation
Share RefCount(Parent) between GhostelTerm and NativeProcess, with direct retain/release calls and destruction on the final reference. Acquire the reader's reference explicitly before spawning its thread. Cover parent recovery, multiple initial references, and concurrent final release.
Retain child controls independently of the PTY backend and use them for native termination instead of signaling recorded numeric PIDs. Use waitid(WNOWAIT) to reserve POSIX child PIDs until termination is disabled under the reaping mutex. Keep Windows process HANDLEs open until final reference release. Make userptr ownership transfer fallible, clean up failed setup, and run Debug finalization after child termination. Cover reaping, retained-handle lifetime, spawn failure, and sentinel cleanup.
emil-e
force-pushed
the
fix/native-child-pid-reuse
branch
from
November 4, 2026 23:08
b5bfa0f to
58b151f
Compare
kill(2) can report ESRCH for a child that is already exiting. The unreaped child still reserves its PID, so that means it is gone. Allocate ChildProcess before spawning, which removes the post-spawn kill-and-reap path from both backends. Hand the Emacs handle's reference out of NativeProcess.init instead of keeping a child field. Reduce the spawn cleanup in Elisp to deleting the pipe on failure.
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
Follow-up to #779, keeping the refcounter refactor and termination fix in separate commits:
RefCount(Parent)for terminal and reader ownership.waitid(WNOWAIT), then disable termination and reap under the signaling mutex so the PID cannot be reused while signaling remains possible.Verification
On the current main-based branch:
Before cherry-picking onto current main, release-runtime tests, Elisp byte-compilation/checkdoc, and Linux/FreeBSD/Windows cross-builds also passed. Non-macOS runtime remains unverified.
Independent static review found no actionable defects. POSIX identity safety requires this control to be the sole consuming reaper.