mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 18:02:13 +03:00
Fix for BUG#24415: Instance manager test im_daemon_life_cycle fails randomly.
The cause of im_daemon_life_cycle.imtest random failures was the following behaviour of some implementations of LINUX threads: let's suppose that a process has several threads (in LINUX threads, there is a separate process for each thread). When the main process gets killed, the parent receives SIGCHLD before all threads (child processes) die. In other words, the parent receives SIGCHLD, when its child is not completely dead. In terms of IM, that means that IM-angel receives SIGCHLD when IM-main is not dead and still holds some resources. After receiving SIGCHLD, IM-angel restarts IM-main, but IM-main failed to initialize, because previous instance (copy) of IM-main still holds server socket (TCP-port). Another problem here was that IM-angel restarted IM-main only if it was killed by signal. If it exited with error, IM-angel thought it's intended / graceful shutdown and exited itself. So, when the second instance of IM-main failed to initialize, IM-angel thought it's intended shutdown and quit. The fix is 1. to change IM-angel so that it restarts IM-main if it exited with error code; 2. to change IM-main so that it returns proper exit code in case of failure. mysql-test/t/disabled.def: Enable im_daemon_life_cycle. server-tools/instance-manager/listener.cc: Set error status if Listener failed to initialize. server-tools/instance-manager/manager.cc: Return exit code from the manager. server-tools/instance-manager/manager.h: Return exit code from the manager. server-tools/instance-manager/mysqlmanager.cc: 1. Restart IM-main if exit code is not EXIT_SUCCESS (0). 2. Log IM-main exit code in case of failure. server-tools/instance-manager/thread_registry.cc: Add support for exit code. server-tools/instance-manager/thread_registry.h: Add support for exit code.
This commit is contained in:
@ -110,8 +110,7 @@ int main(int argc, char *argv[])
|
||||
else
|
||||
#endif
|
||||
|
||||
manager(options);
|
||||
return_value= 0;
|
||||
return_value= manager(options);
|
||||
|
||||
err:
|
||||
options.cleanup();
|
||||
@ -254,26 +253,23 @@ static void daemonize(const char *log_file_name)
|
||||
enum { CHILD_OK= 0, CHILD_NEED_RESPAWN, CHILD_EXIT_ANGEL };
|
||||
|
||||
static volatile sig_atomic_t child_status= CHILD_OK;
|
||||
static volatile sig_atomic_t child_exit_code= 0;
|
||||
|
||||
/*
|
||||
Signal handler for SIGCHLD: reap child, analyze child exit status, and set
|
||||
Signal handler for SIGCHLD: reap child, analyze child exit code, and set
|
||||
child_status appropriately.
|
||||
*/
|
||||
|
||||
void reap_child(int __attribute__((unused)) signo)
|
||||
{
|
||||
int child_exit_status;
|
||||
/* As we have only one child, no need to cycle waitpid */
|
||||
if (waitpid(0, &child_exit_status, WNOHANG) > 0)
|
||||
/* NOTE: As we have only one child, no need to cycle waitpid(). */
|
||||
|
||||
int exit_code;
|
||||
|
||||
if (waitpid(0, &exit_code, WNOHANG) > 0)
|
||||
{
|
||||
if (WIFSIGNALED(child_exit_status))
|
||||
child_status= CHILD_NEED_RESPAWN;
|
||||
else
|
||||
/*
|
||||
As reap_child is not called for SIGSTOP, we should be here only
|
||||
if the child exited normally.
|
||||
*/
|
||||
child_status= CHILD_EXIT_ANGEL;
|
||||
child_exit_code= exit_code;
|
||||
child_status= exit_code ? CHILD_NEED_RESPAWN : CHILD_EXIT_ANGEL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -353,7 +349,9 @@ spawn:
|
||||
else if (child_status == CHILD_NEED_RESPAWN)
|
||||
{
|
||||
child_status= CHILD_OK;
|
||||
log_error("angel(): mysqlmanager exited abnormally: respawning...");
|
||||
log_error("angel(): mysqlmanager exited abnormally (exit code: %d):"
|
||||
"respawning...",
|
||||
(int) child_exit_code);
|
||||
sleep(1); /* don't respawn too fast */
|
||||
goto spawn;
|
||||
}
|
||||
|
Reference in New Issue
Block a user