[pgpool-hackers: 3918] Re: [pgpool-committers: 7808] pgpool: Fix orphan process is left when pgpool is going down.

Tatsuo Ishii ishii at sraoss.co.jp
Wed Jun 9 19:47:42 JST 2021

While testing Pgpool-II for this commit:

I found a bug with handling of child process. In summary, if Pgpool-II
goes down while running follow primary command, some processes kicked
in the follow primary script are left.

I have fixed the bug using setsid(2).

Probably we should think about extensively using setsid(2) like
PostgreSQL already does someday. PostgreSQL creates distinct session
ids for backend process and worker process. This ensures to kill any
process created by those backend and worker process.

Best regards,
Tatsuo Ishii
SRA OSS, Inc. Japan
English: http://www.sraoss.co.jp/index_en.php

From: Tatsuo Ishii <ishii at sraoss.co.jp>
Subject: [pgpool-committers: 7808] pgpool: Fix orphan process is left when pgpool is going down.
Date: Wed, 09 Jun 2021 10:36:34 +0000
Message-ID: <E1lqvZa-0005kJ-U7 at gothos.postgresql.org>

> Fix orphan process is left when pgpool is going down.
> When pgpool is going down while follow primary command is ongoing,
> some process started by follow primary child process could be left.
> The follow primary child calls trigger_failover_command() to run the
> follow primary script by using system(3). Unfortunately the process
> started by system(3) was not tracked by anyone and it was possible
> that the process(es) are left. To reproduce the problem you can edit
> the test script (test,sh) for the regression test
> 075.detach_primary_left_down to change the timeout counter to small
> number, say 1. i.e.,
> change:
> cnt=60
> to
> cnt=1
> To fix the problem, the follow primary child process calls setsid(2)
> to set new session id. When Pgpool-II main goes down, the exit handler
> kills all the process including the process started by system(3), by
> specifying kill(-(follow primary child process pid)).
> Also in the initialization of the follow primary process, unmask
> signals and assign default behavior to each signal (this should have
> been done much earlier).
> Branch
> ------
> master
> Details
> -------
> https://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=810eb97717dc7b265f8ae53478f3a7bb3517318d
> Modified Files
> --------------
> src/main/pgpool_main.c | 69 +++++++++++++++++++++++++++++++++++++++++++++-----
> 1 file changed, 63 insertions(+), 6 deletions(-)

More information about the pgpool-hackers mailing list