Improve setup operations order after fork. (#9365)

The order of setting things up follows some reasoning: Setup signal
handlers first because a signal could fire at any time. Adjust OOM score
before everything else to assist the OOM killer if memory resources are
low.

The trigger for this is a valgrind test failure which resulted with the
child catching a SIGUSR1 before initializing the handler.
This commit is contained in:
Yossi Gottlieb 2021-08-12 14:31:12 +03:00 committed by GitHub
parent 08c46f2b86
commit 1221f7cd5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5845,7 +5845,6 @@ void setupChildSignalHandlers(void) {
act.sa_flags = 0;
act.sa_handler = sigKillChildHandler;
sigaction(SIGUSR1, &act, NULL);
return;
}
/* After fork, the child process will inherit the resources
@ -5875,11 +5874,17 @@ int redisFork(int purpose) {
int childpid;
long long start = ustime();
if ((childpid = fork()) == 0) {
/* Child */
/* Child.
*
* The order of setting things up follows some reasoning:
* Setup signal handlers first because a signal could fire at any time.
* Adjust OOM score before everything else to assist the OOM killer if
* memory resources are low.
*/
server.in_fork_child = purpose;
dismissMemoryInChild();
setOOMScoreAdj(CONFIG_OOM_BGCHILD);
setupChildSignalHandlers();
setOOMScoreAdj(CONFIG_OOM_BGCHILD);
dismissMemoryInChild();
closeChildUnusedResourceAfterFork();
} else {
/* Parent */