Conversation
…before removing from tracking (BYUCamachoLab#50) Root cause: ProcessManager.shutdown_nameserver() and shutdown_daemon() sent the graceful KILL sentinel via the message queue, waited a single fixed join(timeout), and then unconditionally popped the process from self.nameservers/self.daemons and returned True, regardless of whether the underlying OS process had actually exited. A process wedged in a blocking call (e.g. a hardware driver read that never polls its message queue) would be silently orphaned: still holding its port/hardware handle, but reported to callers (and to checkup()) as successfully shut down. Fix: escalate the shutdown the way multiprocessing's own docs recommend - join(2*polling) -> if still alive, terminate() -> join(5) -> if still alive, kill() -> join() - checking is_alive() at each step, and only removing the entry from tracking (via pop()) once the process is confirmed dead (or escalation to SIGKILL is exhausted). The return value now reflects whether the process was actually confirmed dead. Testing: - Added tests/test_manager.py with 4 regression tests covering responsive/wedged process x nameserver/daemon shutdown paths, using fake multiprocessing.Process subclasses (_RespondingProcess polls its queue and exits promptly; _WedgedProcess never polls and can only be stopped by terminate()/kill()). - All 4 new tests pass. tests/test_manager.py is the only active test suite in this repo (other files under tests/ are empty or commented-out legacy files; tests/drivers/** requires hardware SDKs and is correctly excluded via pytest config), confirming no regressions elsewhere. - Verified via git stash that all 4 tests fail/hang against the pre-fix code and pass cleanly against the fix. - Both changed files pass `black --check --diff` (v23.3.0, the version pinned in .pre-commit-config.yaml). AI assistance disclosure: This fix (root-cause analysis, the escalating join/terminate/kill implementation, and the regression tests) was written with the assistance of an AI coding agent (Claude), reviewed and submitted by me. Signed-off-by: agu2347 <94227848+agu2347@users.noreply.github.com>
This branch has not been deployed
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.
Fixes #50.
Root cause
ProcessManager.shutdown_nameserver()andshutdown_daemon()sent the gracefulNoneKILL sentinel via the message queue, waited a single fixedjoin(timeout), and then unconditionally popped the process fromself.nameservers/self.daemonsand returnedTrue— regardless of whether the underlying OS process had actually exited.A process wedged in a blocking call (e.g. a hardware driver read that never polls its message queue, which is exactly the scenario
NameServerRunner/DaemonRunnerare used for) would be silently orphaned: still holding its port or hardware handle, but reported to callers (and to the periodiccheckup()) as successfully shut down.Fix
shutdown_nameserver/shutdown_daemonnow escalate the same waymultiprocessing's own docs recommend:join(2 * msg_polling)after sending the sentinelterminate(), thenjoin(5)kill(), thenjoin()is_alive()one final timeThe entry is only removed from tracking (via
.pop(key, None)) once the process is confirmed dead or escalation toSIGKILLis exhausted, and the return value now reflects whether the process was actually confirmed dead rather than being hardcoded toTrue.Testing
tests/test_manager.pywith 4 regression tests covering responsive/wedged process × nameserver/daemon shutdown paths, using fakemultiprocessing.Processsubclasses:_RespondingProcesspolls its queue and exits promptly on the sentinel (exercises the happy path)._WedgedProcessnever polls and can only be stopped byterminate()/kill()(exercises the bug scenario from Shutdown never confirms the process died, and leaks it if it did not #50).tests/test_manager.pyis the only active test suite in this repo currently (the other files undertests/are empty or commented-out legacy files, andtests/drivers/**requires hardware SDKs and is correctly excluded via the pytest config), so there's no broader regression surface to check.git stashthat all 4 new tests fail (the wedged-process tests hang/timeout, and the responsive-process assertions about actual process death do not hold) against the pre-fix code, and pass cleanly against this fix.black --check --diff(v23.3.0, the version pinned in.pre-commit-config.yaml).AI assistance disclosure
This fix (root-cause analysis, the escalating
join/terminate/killimplementation, and the regression tests) was written with the assistance of an AI coding agent (Claude), and reviewed and submitted by me. Happy to make any changes the maintainers would like.Signed-off-by: agu2347 94227848+agu2347@users.noreply.github.com