Fix race condition with pgpool main and pcp child process.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Mon, 18 Sep 2023 04:15:56 +0000 (13:15 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Mon, 18 Sep 2023 04:15:56 +0000 (13:15 +0900)
When pcp child process is forked off, pgpool main process unblock all
signals.  This could lead to a race condition if a signal is sent to
the pcp process before it sets up signal handlers. Fix is, do not
unblock signals until the signal handlers are set up.

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

src/main/pgpool_main.c
src/pcp_con/pcp_child.c

index 5200daa98e29bb6c3b424234fdd6a7b23e9b7fee..598a9e5392ef8cd6bf39340f917a3b6ef2733b9c 100644 (file)
@@ -812,7 +812,6 @@ pcp_fork_a_child(int *fds, char *pcp_conf_file)
                close(pipe_fds[1]);
 
                /* call PCP child main */
-               POOL_SETMASK(&UnBlockSig);
                health_check_timer_expired = 0;
                reload_config_request = 0;
                pcp_main(fds);
index b1d9211419f38fc706a7bd864b7e2296c8e052fd..f06c9ed1e4ed7d4f2f3228ab9eb4fcfb7d68f40d 100644 (file)
@@ -5,7 +5,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2022     PgPool Global Development Group
+ * Copyright (c) 2003-2023     PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -154,6 +154,11 @@ pcp_main(int *fds)
        /* We can now handle ereport(ERROR) */
        PG_exception_stack = &local_sigjmp_buf;
 
+       /*
+        * Unblock signals
+        */
+       POOL_SETMASK(&UnBlockSig);
+
        ereport(DEBUG1,
                        (errmsg("I am PCP child with pid:%d", getpid())));