File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -842,8 +842,6 @@ func startGatewayWatchdog() {
842842 execProc := os .Args [0 ]
843843 execArgs := append ([]string {"--auto-restart-proc" }, os .Args [1 :]... )
844844
845- interruptLock := sync.Mutex {}
846- shouldShutdown := false
847845 interruptCh := make (chan os.Signal )
848846
849847 go func () {
@@ -864,26 +862,17 @@ func startGatewayWatchdog() {
864862 firstSigIntTime = time .Now ()
865863 }
866864
867- interruptLock .Lock ()
868- if ! shouldShutdown {
869- shouldShutdown = true
870- interruptLock .Unlock ()
871- close (interruptCh )
872- } else {
873- interruptLock .Unlock ()
874- }
865+ interruptCh <- sig
875866 }
876867 case syscall .SIGTERM :
877868 logger .Info ("watchdog received sigterm, waiting for graceful shutdown..." )
878- interruptLock .Lock ()
879- if ! shouldShutdown {
880- interruptCh <- sig
881- }
882- interruptLock .Unlock ()
869+
870+ interruptCh <- sig
883871 }
884872 }
885873 }()
886874
875+ WatchdogLoop:
887876 for {
888877 logger .Info ("starting sub-process" )
889878
@@ -909,26 +898,16 @@ func startGatewayWatchdog() {
909898 logger .Info ("sub-process exited with error" , zap .Error (err ))
910899 }
911900 case sig := <- interruptCh :
912- // if the channel is closed, we are shutting down which is SIGINT
913- if sig == nil {
914- sig = os .Interrupt
915- }
916-
917901 logger .Info ("forwarding signal to sub-process" , zap .String ("signal" , sig .String ()))
918902 _ = cmd .Process .Signal (sig )
919903
920904 err := <- closedCh
921905 if err != nil {
922906 logger .Info ("sub-process exited after signal with error" , zap .Error (err ))
923907 }
924- }
925908
926- interruptLock .Lock ()
927- if shouldShutdown {
928- interruptLock .Unlock ()
929- break
909+ break WatchdogLoop
930910 }
931- interruptLock .Unlock ()
932911
933912 delayTime := 1 * time .Second
934913 logger .Info ("crash detected, restarting" , zap .Duration ("delay" , delayTime ))
You can’t perform that action at this time.
0 commit comments