From 3600ad245fd1f81ba951418eac33ae75c19e2ea9 Mon Sep 17 00:00:00 2001 From: Eno Compton Date: Tue, 8 Nov 2022 12:41:58 -0700 Subject: [PATCH] Exit cleanly when max-sigterm-delay is enabled 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). --- cmd/root.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 7b0884eb3..ab608e098 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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 { @@ -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 }