Fix hung up in pcp_exit_handler of pcp child main.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Sun, 17 Sep 2023 11:45:46 +0000 (20:45 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Sun, 17 Sep 2023 11:45:46 +0000 (20:45 +0900)
pcp_exit_handler is responsible for waiting for exiting pcp child
process. I suspect it is hung up in the wait loop in regression test
001.

https://www.pgpool.net/pipermail/pgpool-hackers/2023-September/004397.html

So I changed it so that it uses waitpid(2) with WNOHANG option.

src/pcp_con/pcp_child.c

index 363b6bd30bcc8fb3759cc68e7ab35450aa7c4662..b1d9211419f38fc706a7bd864b7e2296c8e052fd 100644 (file)
@@ -406,6 +406,7 @@ static RETSIGTYPE
 pcp_exit_handler(int sig)
 {
        pid_t           wpid;
+       ListCell   *lc;
 
        POOL_SETMASK(&AuthBlockSig);
 
@@ -420,15 +421,17 @@ pcp_exit_handler(int sig)
 
        POOL_SETMASK(&UnBlockSig);
 
-       if (list_length(pcp_worker_children) > 0)
+       foreach(lc, pcp_worker_children)
        {
+               int             pid;
+
                do
                {
-                       wpid = wait(NULL);
-               } while (wpid > 0 || (wpid == -1 && errno == EINTR));
-
-               list_free(pcp_worker_children);
+                       wpid = (pid_t) lfirst_int(lc);
+                       pid = waitpid(wpid, NULL, WNOHANG);
+               } while (pid == -1 && errno == EINTR);
        }
+
        pcp_worker_children = NULL;
 
        exit(0);