Graceful Shutdown
Hertz supports graceful shutdown, which is executed as follows:
- Set the state of
engine
toclosed
- Sequential non-blocking trigger callback function
[]OnShutDown
(consistent with standard library net/http) - Shut down the signal listening of the network library
Select
waits for the business coroutine to exit:- For netpoll network library, turn on
ticker
with default 1s (set in netpoll, not changeable at the moment) and check ifactive conn
(business handle exits and connection is not in blocking read state) is 0 at regular intervals; for go net network library, turn off listening and do not process the connection. - Triggered by the context of
ExitWaitTime
, default 5s
- For netpoll network library, turn on
- Uniformly add
Connection:Close header
to request packets in the process of closing
If you want to modify the wait timeout, you can configure it with server.WithExitWaitTime()
.
If you want to register the hook
function, you can do so by getting the Engine
and registering it:
h.Engine.OnShutdown = append(h.Engine.OnShutdown, shutDownFunc)
Last modified
August 15, 2022
: perf(docs): compressed picture size (#300) (2f9acd5)