pgpool2.git / summary / log / commit / refs
commit 7aa5b726ba24e97fa4c6535f3ea9ab1e8e9bbb47
Author: Tatsuo Ishii <ishii@postgresql.org>
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/main.c | 5 +++++
src/protocol/child.c | 18 +++++++++++++++++-
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/src/main/main.c b/src/main/main.c
index 9b81f738c..b826deaff 100644
--- a/src/main/main.c
+++ b/src/main/main.c
@@ -1591,6 +1591,11 @@ static RETSIGTYPE exit_handler(int sig)
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++)
{
pid_t pid = process_info[i].pid;
diff --git a/src/protocol/child.c b/src/protocol/child.c
index 33f3273e7..f84b46219 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
@@ -85,6 +85,9 @@ volatile sig_atomic_t exit_request = 0;
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;
@@ -134,6 +137,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;
/* Initialize my backend status */
pool_initialize_private_backend_status();
@@ -1279,6 +1287,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: 73934a3bdad1]