Fix for 0000249: watchdog sometimes fails de-escalation.
authorMuhammad Usama <m.usama@gmail.com>
Wed, 4 Jan 2017 13:23:33 +0000 (18:23 +0500)
committerMuhammad Usama <m.usama@gmail.com>
Wed, 4 Jan 2017 13:35:29 +0000 (18:35 +0500)
The logic in pgpool-II main process exit_handler and terminate_all_childrens was
not making sure that pgpool-II main process should only exit after all its
children have exited. And the problem occurs when the main process shutdowns
itself before watchdog and de-escalation child processes.

The solution is to use the waitpid() system call without WNOHANG option.

main.c

diff --git a/main.c b/main.c
index bedb0aacf8f6a27aa2513a7345b519d6da4385f9..d06de306b37ef91ed393824b3d1916834fd39eb0 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1465,7 +1465,7 @@ static void myexit(int code)
                {
                        pid_t ret_pid;
 
-                       wpid = waitpid(-1, &ret_pid, WNOHANG);
+                       wpid = waitpid(-1, &ret_pid, 0);
                } while (wpid > 0 || (wpid == -1 && errno == EINTR));
 
                if (wpid == -1 && errno != ECHILD)
@@ -1751,7 +1751,7 @@ static RETSIGTYPE exit_handler(int sig)
     {
                pid_t ret_pid;
 
-        wpid = waitpid(-1, &ret_pid, WNOHANG);
+        wpid = waitpid(-1, &ret_pid, 0);
     } while (wpid > 0 || (wpid == -1 && errno == EINTR));
 
     if (wpid == -1 && errno != ECHILD)