-
Notifications
You must be signed in to change notification settings - Fork 413
fix: remove os.Exit from mail watch signal handler #268
Copy link
Copy link
Labels
domain/mailPR touches the mail domainPR touches the mail domain
Description
Problem
The mail watch command uses os.Exit(0) in its signal handler to terminate the program when receiving Ctrl+C. This approach has several drawbacks:
- Not testable -
os.Exitterminates the process immediately, preventing unit tests from verifying shutdown behavior - Bypasses cleanup - Deferred cleanup functions in the call stack are not executed
- Unidiomatic - CLI tools should use context cancellation for graceful shutdown
Solution
Replace os.Exit(0) with a graceful shutdown mechanism using:
context.WithCancelto propagate cancellation to the WebSocket client- A
shutdownBySignalchannel to coordinate between signal handler and main goroutine - Proper
defer signal.Stop(sigCh)for resource cleanup
Changes
shortcuts/mail/mail_watch.go: Removeos.Exit(0), add context-based shutdown coordination
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
domain/mailPR touches the mail domainPR touches the mail domain