chore: refactor signal sigterm and sigint (#3632)

master
Kevin Wan 1 year ago committed by GitHub
parent 95b7a3d3ce
commit 88f60d7736
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -52,10 +52,10 @@ func WrapUp() {
wrapUpListeners.notifyListeners()
}
func gracefulStop(signals chan os.Signal) {
func gracefulStop(signals chan os.Signal, sig syscall.Signal) {
signal.Stop(signals)
logx.Info("Got signal SIGTERM, shutting down...")
logx.Infof("Got signal %d, shutting down...", sig)
go wrapUpListeners.notifyListeners()
time.Sleep(wrapUpTime)
@ -63,7 +63,7 @@ func gracefulStop(signals chan os.Signal) {
time.Sleep(delayTimeBeforeForceQuit - wrapUpTime)
logx.Infof("Still alive after %v, going to force kill the process...", delayTimeBeforeForceQuit)
syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
_ = syscall.Kill(syscall.Getpid(), sig)
}
type listenerManager struct {

@ -34,14 +34,12 @@ func init() {
profiler.Stop()
profiler = nil
}
case syscall.SIGTERM, syscall.SIGINT:
select {
case <-done:
// already closed
default:
close(done)
}
gracefulStop(signals)
case syscall.SIGTERM:
stopOnSignal()
gracefulStop(signals, syscall.SIGTERM)
case syscall.SIGINT:
stopOnSignal()
gracefulStop(signals, syscall.SIGINT)
default:
logx.Error("Got unregistered signal:", v)
}
@ -53,3 +51,12 @@ func init() {
func Done() <-chan struct{} {
return done
}
func stopOnSignal() {
select {
case <-done:
// already closed
default:
close(done)
}
}

Loading…
Cancel
Save