NOTE
1.10 Redis Signal Handling
How Redis handles SIGTERM/SIGINT, crash signals, and killed background child processes.
This is a historical learning note and may contain outdated or incomplete understanding.
1. Handling SIGTERM and SIGINT
Tell Redis to shut down gracefully.
- If a background child process is saving an RDB file or performing an AOF rewrite, kill that child process.
- If AOF is enabled, call
fsyncon the AOF file descriptor to flush the disk buffer. - If RDB is enabled, save the RDB synchronously in a blocking manner.
- If the RDB cannot be saved, the Redis server keeps running to prevent data loss.
- If the server is a background process, delete the pid file.
- If a Unix domain socket is enabled, delete it.
- Exit with return code 0.
2. Handling SIGSEGV, SIGBUS, SIGFPE, and SIGILL
Redis crashes.
- Generate a bug report in the log file, including a stack trace, dump of registers, and information about the state of clients.
- If the server is a background process, delete the pid file.
- Unregister its own signal handler and send the same signal to itself. This executes the default signal-handling mechanism, such as dumping the core to the file system.
3. What If a Child Process Is Killed?
- If the child process is performing an AOF rewrite, Redis treats this as an error, ignores the AOF file, and restarts the AOF rewrite.
- If the child process is saving an RDB file, Redis:
- continues serving read commands;
- returns a
MISCONFIGerror for all write commands.
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub