From: Tatsuo Ishii Date: Sun, 17 Sep 2023 11:45:46 +0000 (+0900) Subject: Fix hung up in pcp_exit_handler of pcp child main. X-Git-Tag: V4_5_0_BETA1~22 X-Git-Url: http://git.postgresql.org/gitweb/static/help.php?a=commitdiff_plain;h=2ee501190928f149f67dcb537855071091e27caa;p=pgpool2.git Fix hung up in pcp_exit_handler of pcp child main. 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. --- diff --git a/src/pcp_con/pcp_child.c b/src/pcp_con/pcp_child.c index 363b6bd30..b1d921141 100644 --- a/src/pcp_con/pcp_child.c +++ b/src/pcp_con/pcp_child.c @@ -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);