fix(system): redo signal forwarding for processes#125
fix(system): redo signal forwarding for processes#125water-sucks merged 2 commits intonix-community:mainfrom
Conversation
WalkthroughRefactors signal forwarding for subprocesses: Changes
Sequence DiagramsequenceDiagram
participant Main
participant SigHandler as Signal Handler (goroutine)
participant Child as Child Process / SSH Session
Main->>Child: Start() / Start SSH session
Main->>SigHandler: spawn signal-forwarding goroutine
Note over Main,SigHandler: SigHandler listens on OS signal channel
SigHandler->>SigHandler: receive OS signal
alt local process
SigHandler->>Child: send syscall signal (SIGINT/SIGTERM)
else ssh session
SigHandler->>SigHandler: map via osSignalToSSHSignal()
SigHandler->>Child: send SSH signal string (session.Signal)
end
Child->>Main: Exit status / session end
Main->>SigHandler: close signal channel (stop forwarding)
SigHandler->>SigHandler: loop terminates
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🔇 Additional comments (4)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
internal/system/local.go (2)
42-61: Signal forwarding implementation looks correct.The approach of using
Start()followed byWait()with a signal-forwarding goroutine properly addresses the missing local signal forwarding. The cleanup viadeferensures the signal handler is unregistered and the goroutine exits cleanly.One minor refinement: registering the signal handler before calling
Start()would eliminate a small race window where signals arriving betweenStart()andNotify()might not be forwarded. The existing nil-check oncommand.Processalready handles this safely.Optional: Eliminate signal race
Move the signal setup before
Start():+ sigs := make(chan os.Signal, 1) + signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) + defer func() { + signal.Stop(sigs) + close(sigs) + }() + if err := command.Start(); err != nil { return 0, err } - sigs := make(chan os.Signal, 1) - signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) - defer func() { - signal.Stop(sigs) - close(sigs) - }() - go func() { for sig := range sigs { if command.Process != nil { _ = command.Process.Signal(sig) } } }()
56-56: Consider logging signal forwarding errors.While ignoring the error from
Process.Signal()is reasonable for signal forwarding, logging failures would aid debugging if signal delivery issues arise.- _ = command.Process.Signal(sig) + if err := command.Process.Signal(sig); err != nil { + l.logger.Debugf("failed to forward signal %v: %v", sig, err) + }internal/system/ssh.go (1)
353-384: Signal mapping correctly implements SSH protocol requirements.The
osSignalToSSHSignal()function properly maps OS signals to SSH signal names (without the "SIG" prefix), fixing the bug described in the PR. The mapped signals align with RFC 4254 section 6.10.The default case returning an empty string for unmapped signals is reasonable since not all OS signals have SSH protocol equivalents. However, logging unmapped signals would help identify unexpected signal types during debugging.
default: + // Log unmapped signals for debugging + // Most signals (SIGSTOP, SIGCONT, SIGCHLD, etc.) cannot be forwarded via SSH return "" }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
internal/system/local.go(2 hunks)internal/system/ssh.go(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Build/Test
🔇 Additional comments (1)
internal/system/ssh.go (1)
336-339: Simplified signal forwarding is cleaner.The direct
for sig := range sigChloop is more straightforward than the previous approach and correctly terminates when the channel is closed by the defer on line 332.
2166b2f to
066b98f
Compare
Description
Signal forwarding was not occurring for spawned processes (i.e. switch-to-configuration). This was because of two bugs:
LocalSystemabstraction.os.Signaltype directly to its debug representation rather than using the SSH package constants that don't have the prefixedSIG.This PR fixes both those issues.
Summary by CodeRabbit