Skip to content

Commit

Permalink
Exit cleanly when max-sigterm-delay is enabled
Browse files Browse the repository at this point in the history
When the client closes cleanly and max-sigterm-delay is enabled, the
Proxy will exit with a 0 exit code on SIGTERM or SIGINT.

Otherwise, the Proxy will exit with 143 (SIGTERM) or 130 (SIGINT).
  • Loading branch information
enocom committed Nov 8, 2022
1 parent b3cc588 commit 3600ad2
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,11 +617,6 @@ func runSignalWrapper(cmd *Command) error {
case p = <-startCh:
cmd.logger.Infof("The proxy has started successfully and is ready for new connections!")
}
defer func() {
if cErr := p.Close(); cErr != nil {
cmd.logger.Errorf("error during shutdown: %v", cErr)
}
}()

notify := func() {}
if cmd.healthCheck {
Expand Down Expand Up @@ -672,5 +667,14 @@ func runSignalWrapper(cmd *Command) error {
default:
cmd.logger.Errorf("The proxy has encountered a terminal error: %v", err)
}
cErr := p.Close()
if cErr != nil {
cmd.logger.Errorf("error during shutdown: %v", cErr)
}
// If Close succeeded and WaitOnClose is enabled, return no error to get a 0
// exit status.
if cErr == nil && cmd.conf.WaitOnClose != 0 {
return nil
}
return err
}

0 comments on commit 3600ad2

Please sign in to comment.