pgpool2.git / summary / log / commit / refs

commit    2fba0c6a5a9934218dab154c9ae09deab0d42496
Author:   Tatsuo Ishii <ishii@postgresql.org>
Date:     Tue Dec 06 04:28:36 2016 +0000

    Fix a race condition in a signal handler per bug 265.
    
    In child.c there's signal handler which calls elog. Since the signal
    handler is not blocked against other signals while processing, deadlock
    could occur in the system calls in the pgpool shutdown sequence. To
    fix the problem, now the signal handler is blocked by using
    POOL_SETMASK.
    
    Ideally we should avoid calling elog in signal handlers though.


src/protocol/child.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/protocol/child.c b/src/protocol/child.c index 96d18a697..843db9281 100644 --- a/src/protocol/child.c +++ b/src/protocol/child.c @@ -916,7 +916,11 @@ static POOL_CONNECTION_POOL *connect_backend(StartupPacket *sp, POOL_CONNECTION */ static RETSIGTYPE die(int sig) { - int save_errno = errno; + int save_errno; + + POOL_SETMASK(&BlockSig); + + save_errno = errno; ereport(LOG, (errmsg("child process received shutdown request signal %d", sig))); @@ -944,6 +948,7 @@ static RETSIGTYPE die(int sig) case SIGINT: /* fast shutdown */ case SIGQUIT: /* immediate shutdown */ + POOL_SETMASK(&UnBlockSig); child_exit(POOL_EXIT_NO_RESTART); break; default: @@ -955,6 +960,7 @@ static RETSIGTYPE die(int sig) } errno = save_errno; + POOL_SETMASK(&UnBlockSig); } /* [parent: cc452ad0cb3b]