fix(signal): Improve signal handling robustness on shutdown - #7
Merged
Conversation
Refactors signal forwarding across processes and TUI interactions to ensure graceful shutdowns. In `exec.go`, we now consistently forward SIGINT/SIGTERM signals rather than escalating to a hard kill, respecting child process termination sequences (e.g., docker compose). The `tui.go` model also updates to track repeated stop attempts and utilize incremental signaling before resorting to force termination.
There was a problem hiding this comment.
Pull request overview
Refactors shutdown/signal-handling behavior so the CLI and its TUI remain alive during termination and allow child processes to complete graceful shutdown (especially for Docker Compose workflows), rather than escalating quickly to hard kills.
Changes:
- Update
runWithSignalForwardingto forward repeated SIGINT/SIGTERM signals instead of escalating to SIGKILL internally. - Add TUI stop-attempt tracking to forward SIGINT multiple times before force-killing on a final attempt.
- Improve TUI status bar messaging to reflect remaining stop attempts before forced quit.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tui.go | Adds stopPresses tracking and adjusts quit/stop behavior to forward SIGINT before force-killing on repeated attempts. |
| exec.go | Changes signal-forwarding behavior to forward every received SIGINT/SIGTERM to the child (removing internal escalation to SIGKILL). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
129
to
+132
| for { | ||
| select { | ||
| case sig := <-sigCh: | ||
| if !forwarded { | ||
| forwarded = true | ||
| _ = cmd.Process.Signal(sig) | ||
| } else { | ||
| _ = cmd.Process.Kill() | ||
| } | ||
| _ = cmd.Process.Signal(sig) |
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.
🧪 Fix: Improve Signal Handling Robustness on Shutdown
Description
This change refactors signal handling across process execution and TUI interactions to significantly improve robustness during application shutdown sequences. The primary goal is to ensure that child processes are managed using graceful termination methods (e.g.,
SIGINT,SIGTERM) rather than relying on hard kills, improving compatibility with modern container orchestration tools like Docker Compose.🚀 Changes Implemented
The signal forwarding logic has been enhanced in multiple areas:
exec.go): The corerunWithSignalForwardinglogic is modified to consistently capture and forward all received SIGINT/SIGTERM signals. This prevents the forceful escalation to a hard kill, allowing child processes to execute their designated graceful shutdown routines.tui.go): The model now accurately tracks repeated stop attempts. Instead of immediately force-terminating on initial failure, it utilizes an incremental signaling approach before resorting to forceful measures, ensuring better adherence to structured container shutdown signals.✨ How This Improves Robustness
Previously, certain workflows could result in abrupt process termination when signals were received (especially during resource cleanup or coordinated shutdowns). These changes ensure that the application respects the intended lifecycle provided by tools like
docker composeand underlying operating systems, making the entire runtime more stable and predictable.✅ Checklist