Skip to content

Commit f8cf437

Browse files
committed
Remove signal handling channels correctly
The "break" here only break out from the inner select statement. The for loop is keep running and signal.Stop() won't be called. Seems that is the cause of #198. Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent c3bc513 commit f8cf437

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

machine.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,13 +948,16 @@ func (m *Machine) setupSignals() {
948948
signal.Notify(sigchan, signals...)
949949

950950
go func() {
951+
ForLoop:
951952
for {
952953
select {
953954
case sig := <-sigchan:
954-
m.logger.Printf("Caught signal %s", sig)
955+
m.logger.Debugf("Caught signal %s", sig)
956+
// Some signals kill the process, some of them are not.
955957
m.cmd.Process.Signal(sig)
956958
case <-m.exitCh:
957-
break
959+
// And if a signal kills the process, we can stop this for loop and remove sigchan.
960+
break ForLoop
958961
}
959962
}
960963

0 commit comments

Comments
 (0)