pgpool2.git / summary / log / commit / refs

commit    79b8d94510fd939f8fcd0cffb3fef63248aa3edb
Author:   Tatsuo Ishii <ishii@postgresql.org>
Commit:   Muhammad Usama <m.usama@gmail.com>
Date:     Sat Mar 29 08:36:50 2014 +0000

    Close listen socket when smart shutdown request is made.
    
    When smart shutdown process starts, pgpool children still listen on
    the port and clients can send further connection requests which fail
    in the end. Which is not only waste of time, but also prevents a load
    balancer which sits in front of pgpool from realizing the pgpool is
    going down.
    
    Problem analyzed and patch provided by Junegunn Choi in pgpool-hackers
    474, and enhanced to take care not only inet domain socket but UNIX
    domain socket by me.


src/main/pgpool_main.c | 7 ++++++- src/protocol/child.c | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/pgpool_main.c b/src/main/pgpool_main.c index f449d9192..41e012123 100644 --- a/src/main/pgpool_main.c +++ b/src/main/pgpool_main.c @@ -932,7 +932,12 @@ static RETSIGTYPE exit_handler(int sig) return; } exiting = 1; - + + /* Close listen socket */ + pool_log("pgpool main: close listen socket"); + close(inet_fd); + close(unix_fd); + for (i = 0; i < pool_config->num_init_children; i++) { diff --git a/src/protocol/child.c b/src/protocol/child.c index c9c669c98..360783a54 100644 --- a/src/protocol/child.c +++ b/src/protocol/child.c @@ -5,7 +5,7 @@ * pgpool: a language independent connection pool server for PostgreSQL * written by Tatsuo Ishii * - * Copyright (c) 2003-2013 PgPool Global Development Group + * Copyright (c) 2003-2014 PgPool Global Development Group * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby @@ -101,6 +101,9 @@ static volatile sig_atomic_t alarm_enabled = false; static int idle; /* non 0 means this child is in idle state */ static int accepted = 0; +static int child_inet_fd = 0; +static int child_unix_fd = 0; + extern int myargc; extern char **myargv; @@ -153,6 +156,11 @@ void do_child(int unix_fd, int inet_fd) pool_set_nonblock(inet_fd); } #endif + if (inet_fd) + { + child_inet_fd = inet_fd; + } + child_unix_fd = unix_fd; /* Create per loop iteration memory context */ ChildLoopMemoryContext = AllocSetContextCreate(TopMemoryContext, @@ -1176,6 +1184,14 @@ static RETSIGTYPE die(int sig) switch (sig) { case SIGTERM: /* smart shutdown */ + /* Refuse further requests by closing listen socket */ + if (child_inet_fd) + { + pool_log("die: close listen socket"); + close(child_inet_fd); + } + close(child_unix_fd); + if (idle == 0) { pool_debug("child receives smart shutdown request but it's not in idle state"); [parent: 5bbdfdde6962]