Skip to content

Commit

Permalink
Fix Signal deadlock that prevented shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
karlkfi committed May 2, 2020
1 parent 971c6d6 commit 94ae32b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 19 deletions.
1 change: 0 additions & 1 deletion cmd/kubexit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ func main() {
// ShutdownWithTimeout doesn't block until timeout
if err != nil {
log.Printf("Error: failed to shutdown: %v\n", err)
return
}
}))
if err != nil {
Expand Down
20 changes: 2 additions & 18 deletions pkg/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,6 @@ func (s *Supervisor) Wait() error {
return s.cmd.Wait()
}

func (s *Supervisor) Signal(sig os.Signal) error {
s.startStopLock.Lock()
defer s.startStopLock.Unlock()

// Process set by Start
if s.cmd.Process == nil {
return errors.New("cannot signal unstarted child process")
}

err := s.cmd.Process.Signal(sig)
if err != nil {
return fmt.Errorf("failed to signal child process: %v", err)
}
return nil
}

func (s *Supervisor) ShutdownNow() error {
s.startStopLock.Lock()
defer s.startStopLock.Unlock()
Expand All @@ -112,7 +96,7 @@ func (s *Supervisor) ShutdownNow() error {
log.Println("Killing child process...")
// TODO: Use Process.Kill() instead?
// Sending Interrupt on Windows is not implemented.
err := s.Signal(syscall.SIGKILL)
err := s.cmd.Process.Signal(syscall.SIGKILL)
if err != nil {
return fmt.Errorf("failed to kill child process: %v", err)
}
Expand All @@ -133,7 +117,7 @@ func (s *Supervisor) ShutdownWithTimeout(timeout time.Duration) error {
}

log.Println("Terminating child process...")
err := s.Signal(syscall.SIGTERM)
err := s.cmd.Process.Signal(syscall.SIGTERM)
if err != nil {
return fmt.Errorf("failed to terminate child process: %v", err)
}
Expand Down

0 comments on commit 94ae32b

Please sign in to comment.