chore: refactor signal sigterm and sigint (#3632)

This commit is contained in:
Kevin Wan
2023-10-15 23:24:17 +08:00
committed by GitHub
parent 95b7a3d3ce
commit 88f60d7736
2 changed files with 18 additions and 11 deletions

View File

@@ -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)
}
}