fix(cli_control): harden process kill and error paths - #155
Merged
Conversation
mkoura
commented
Aug 17, 2026
Collaborator
- trust start script PID only while instance is starting; a finished start leaves a stale PID that the kernel may recycle
- reject PID <= 0 from pidfile; 0 or negative would signal the whole process group
- escalate SIGTERM -> SIGKILL with bounded waits instead of a blind 0.5s sleep; report a survivor as failure
- catch OSError from Popen in start/stop/restart helpers; a script without exec bit was an unhandled traceback
- undelay instance in finally; a raised exception used to leave the delay file behind and abort the whole stopall loop
- check running state only while the instance is delayed (TOCTOU)
- validate action flags and supervisorctl presence before delaying
- tolerate malformed testnet.json in ls; warn instead of crashing
- shlex-quote sourced env values; unquoted workdir path could break quoting or execute command substitution
- pass argv lists to run_command; str splitting broke on workdir paths with spaces
- remove stale pidfile also on foreground start
There was a problem hiding this comment.
Pull request overview
This PR hardens the testnet CLI control/create flows to avoid unsafe PID signaling, improve process termination reliability, and make command execution and instance listing more robust in the presence of malformed/missing files.
Changes:
- Adds PID validation helpers and a bounded SIGTERM→SIGKILL escalation path when stopping “starting” instances.
- Switches command execution to argv lists (avoids
.split()issues on paths with spaces) and expands error handling forOSError. - Quotes exported environment values for safe shell sourcing and makes
lsresilient to malformed/missingtestnet.json.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/cardonnay/cli_create.py |
Quotes sourced env values, uses argv lists for run_command, and adjusts PID file handling for start paths. |
src/cardonnay/cli_control.py |
Implements PID validation + safer kill logic, hardens stop/restart execution paths, improves ls robustness, and refactors action/delay handling. |
Suppressed comments (1)
src/cardonnay/cli_control.py:302
- The earlier guard against negative
instance_numwas removed. With a negative value,delay_instance()will create adelay_stat-<n>file, triggering warnings inget_delay_instances()and potentially interfering with instance coordination. Reject negative instance numbers up front.
workdir_pl = ca_utils.get_workdir(workdir=workdir).absolute()
if not (stop or restart or restart_nodes):
LOGGER.error("No valid action was selected.")
return 1
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- trust start script PID only while instance is starting; a finished start leaves a stale PID that the kernel may recycle - reject PID <= 0 from pidfile; 0 or negative would signal the whole process group - escalate SIGTERM -> SIGKILL with bounded waits instead of a blind 0.5s sleep; report a survivor as failure - catch OSError from Popen in start/stop/restart helpers; a script without exec bit was an unhandled traceback - undelay instance in finally; a raised exception used to leave the delay file behind and abort the whole stopall loop - check running state only while the instance is delayed (TOCTOU) - validate action flags and supervisorctl presence before delaying - tolerate malformed testnet.json in ls; warn instead of crashing - shlex-quote sourced env values; unquoted workdir path could break quoting or execute command substitution - pass argv lists to run_command; str splitting broke on workdir paths with spaces - remove stale pidfile also on foreground start
mkoura
force-pushed
the
fix/cli-control-hardening
branch
from
August 17, 2026 12:55
2f2af14 to
64f23de
Compare
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.