mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
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:
parent
08c46f2b86
commit
1221f7cd5e
13
src/server.c
13
src/server.c
@ -5845,7 +5845,6 @@ void setupChildSignalHandlers(void) {
|
|||||||
act.sa_flags = 0;
|
act.sa_flags = 0;
|
||||||
act.sa_handler = sigKillChildHandler;
|
act.sa_handler = sigKillChildHandler;
|
||||||
sigaction(SIGUSR1, &act, NULL);
|
sigaction(SIGUSR1, &act, NULL);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* After fork, the child process will inherit the resources
|
/* After fork, the child process will inherit the resources
|
||||||
@ -5875,11 +5874,17 @@ int redisFork(int purpose) {
|
|||||||
int childpid;
|
int childpid;
|
||||||
long long start = ustime();
|
long long start = ustime();
|
||||||
if ((childpid = fork()) == 0) {
|
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;
|
server.in_fork_child = purpose;
|
||||||
dismissMemoryInChild();
|
|
||||||
setOOMScoreAdj(CONFIG_OOM_BGCHILD);
|
|
||||||
setupChildSignalHandlers();
|
setupChildSignalHandlers();
|
||||||
|
setOOMScoreAdj(CONFIG_OOM_BGCHILD);
|
||||||
|
dismissMemoryInChild();
|
||||||
closeChildUnusedResourceAfterFork();
|
closeChildUnusedResourceAfterFork();
|
||||||
} else {
|
} else {
|
||||||
/* Parent */
|
/* Parent */
|
||||||
|
Loading…
Reference in New Issue
Block a user