-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to make gracefulStop waiting? #4100
Comments
func signalHandler() {
// signal handler
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
for {
s := <-c
switch s {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
// do what you want
return
case syscall.SIGHUP:
default:
return
}
}
} |
But report: https://gityub. Kom/jaron-ie/jzero/bb/main/daemon/daemon. Go |
go-zero already has this logic, but the function 'gracefulStop' did not execute as expected. core/proc/signals.go func init() {
go func() {
// https://golang.org/pkg/os/signal/#Notify
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGUSR1, syscall.SIGUSR2, syscall.SIGTERM, syscall.SIGINT)
for {
v := <-signals
switch v {
case syscall.SIGUSR1:
dumpGoroutines(fileCreator{})
case syscall.SIGUSR2:
profiler := StartProfile()
time.AfterFunc(profileDuration, profiler.Stop)
case syscall.SIGTERM:
stopOnSignal()
gracefulStop(signals, syscall.SIGTERM)
case syscall.SIGINT:
stopOnSignal()
gracefulStop(signals, syscall.SIGINT)
default:
logx.Error("Got unregistered signal:", v)
}
}
}()
} |
waitForCalled := proc.AddWrapUpListener(func() {
fmt.Println("wrap up start...")
time.Sleep(5 * time.Second)
fmt.Println("wrap up done")
})
waitForCalled() |
waitForCalled() will block the flow, before |
Call it after server started. |
server.Start() will block the main thread. |
the code is generated by goctl, and just added
test()
function.build and run it in Linux,then send SIGNTERM, it print log
Why it does not wait the listener's func done?
How to make it wait?
The text was updated successfully, but these errors were encountered: