Closed answergong closed 5 months ago
What behaviors do you expect on graceful shutdown?
It serves all the ongoing requests and exit? Do you have ongoing requests?
What behaviors do you expect on graceful shutdown?
It serves all the ongoing requests and exit? Do you have ongoing requests?
thanks for you reply! i have two api func ;in one api ,i let it sleep 60s ;another is qiuckly return the response; and the main.go's code is on the above(the code is from the test code "greet",generate by "goctl api new greet"); when i request the two api.one is quickly return response; another is in procing(wait the sleep) ;in this time ,i opeate ctrl +c(or kill) the main func ,the program shutdown Immediately(i hope the program should hold on 60s to wait the running api.but it isn't ),so i think it has something wrong; I looked up zero's documentation and he said server.start() has implemented elegant shutdown.
That's not graceful shutdown.
If your program stuck, how to stop it?
Graceful shutdown means finishing ongoing requests, not accepting new requests, then quit.
thanks, I understand what you mean, but I do have a ongoing request(sleep 60s). when I was released to terminate main.go, I thought he should wait for 60 s before the program quit. this is elegant closure, but the fact is that he did not wait, but directly quit. do you think this situation should not wait? i think graceful showdown should wait the 60s ;
There is a method SetTimeToForceQuit
, but if too long, rolling update will take too much time.
There is a method
SetTimeToForceQuit
, but if too long, rolling update will take too much time.
I don't think my problem is that I have reached the maximum forced exit time. My phenomenon is: when I send a termination request, the program immediately returns and does not wait for the end of my processing request; If you have some time ,i hope you can run the test code locally (the code is generate by "goctl api new greet", then add a new handler func,in the func sleep some time ),i think you will get the some result as me ;thanks you very much!
When receiving SIGTERM
in Linux
or Darwin
, it will close gracefully.
code:
https://github.com/zeromicro/go-zero/blob/5208def65ae88c70b87f547696a804ee9a3e0bc1/core/proc/signals.go#L1-L2
https://github.com/zeromicro/go-zero/blob/5208def65ae88c70b87f547696a804ee9a3e0bc1/core/proc/signals.go#L38-L46
http.Server provide func RegisterOnShutdown to clean resources when it shutdown ,is there any ways in gozero to do things like so ? I think this also part of gracefully exit stuffs
http.Server provide func RegisterOnShutdown to clean resources when it shutdown ,is there any ways in gozero to do things like so ? I think this also part of gracefully exit stuffs
Reference here: https://github.com/zeromicro/go-zero/blob/95a5f6449334f67d835fe176e361f0745f1a0961/rest/internal/starter.go#L41-L45
http.Server provide func RegisterOnShutdown to clean resources when it shutdown ,is there any ways in gozero to do things like so ? I think this also part of gracefully exit stuffs
Reference here:
thanks
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.
I tested the http service myself, use ctrl_c and kill pid to cancel the program, but it also exited directly, and did not wait for the coroutine processing of the processing program to end before exiting;
I read the documentation and said that the server.Start() method of go zero will automatically handle graceful restarts, but I didn't find any problems.
the code is automatic generation by (goctl api new greet)
the code is