Gracefully Shutdown of Server Process

This page introduces how to gracefully shut down a working server process using signals.

When you start the server processing with Server.Run(Handler), it will block and wait for incoming signals.

There are two types of signals that can be sent to a running program to gracefully shut down the process.

  • TSTP: This signal tells the Server to stop handling new tasks.
  • TERM or INT: This signal tells the Server to terminate (i.e., shut down).

It is recommended to send the TSTP signal first to stop handling new tasks, and wait for all ongoing tasks to complete before sending the TERM signal to terminate the program.

Use the kill command to send signals.

kill -TSTP  # Stop handling new tasks

kill -TERM  # Shut down the server

Note: If the TERM or INT signal is sent without sending the TSTP signal, the Server will start a timer and wait for 8 seconds for all workers to complete (to customize this timeout duration, use the ShutdownTime configuration). If there are any workers unfinished within that time frame, the tasks will revert to pending state and be handled again upon program restart.

Note: Currently, Windows does not support the TSTP signal.