Problem
The --scan command iterates through the entire port range (default 1000 ports) and can take significant time. If interrupted (Ctrl+C), there is no signal handling:
- Partial data may be written
- No cleanup performed
- User gets no feedback about interruption
Current Behavior
$ port-selector --scan
# User presses Ctrl+C during scan
# Process terminates immediately
# Allocations file may be in inconsistent state
Proposed Solution
Add signal handling for SIGINT and SIGTERM:
func runScan(...) error {
ctx, cancel := context.WithCancel(context.Background())
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigChan
fmt.Fprintln(os.Stderr, "\nInterrupted, saving partial results...")
cancel()
}()
// Use ctx in scan loop
for port := start; port <= end; port++ {
select {
case <-ctx.Done():
return savePartialResults()
default:
// scan port
}
}
}
Acceptance Criteria
Priority
Low - edge case, but improves robustness
Problem
The
--scancommand iterates through the entire port range (default 1000 ports) and can take significant time. If interrupted (Ctrl+C), there is no signal handling:Current Behavior
Proposed Solution
Add signal handling for
SIGINTandSIGTERM:Acceptance Criteria
--scanPriority
Low - edge case, but improves robustness