pgpool2.git / summary / log / commit / refs
commit 39eb90fe199d03253b99bec38d85c40f66aa55ab
Author: Tatsuo Ishii <ishii@sraoss.co.jp>
Date: Tue Aug 11 01:26:43 2020 +0000
Fix connection_life_time does not work.
If master node is not 0 (this could happen in the case when primary
node is not 0 in streaming replication mode for example), pgpool
failed to find connection_life_time timer because the timer was set
only in virtual_master_node, which could be changed after session ends
since query context is not there any more.
To fix this, connection_life_time timer is set to all valid nodes.
Regression test is also added.
Discussion: https://www.pgpool.net/pipermail/pgpool-general/2020-August/007242.html
src/protocol/pool_connection_pool.c | 7 ++-
.../tests/031.connection_life_time/test.sh | 69 ++++++++++++++++++++++
2 files changed, 74 insertions(+), 2 deletions(-)
diff --git a/src/protocol/pool_connection_pool.c b/src/protocol/pool_connection_pool.c
index 3533628e3..0c77cbfca 100644
--- a/src/protocol/pool_connection_pool.c
+++ b/src/protocol/pool_connection_pool.c
@@ -347,8 +347,11 @@ pool_connection_pool_timer(POOL_CONNECTION_POOL * backend)
(errmsg("setting backend connection close timer"),
errdetail("close time %ld", time(NULL))));
- MASTER_CONNECTION(backend)->closetime = time(NULL); /* set connection close
- * time */
+ /* Set connection close time */
+ for (i = 0; i < NUM_BACKENDS; i++)
+ {
+ CONNECTION_SLOT(backend, i)->closetime = time(NULL);
+ }
if (pool_config->connection_life_time == 0)
return;
diff --git a/src/test/regression/tests/031.connection_life_time/test.sh b/src/test/regression/tests/031.connection_life_time/test.sh
new file mode 100755
index 000000000..b2cc46e01
--- /dev/null
+++ b/src/test/regression/tests/031.connection_life_time/test.sh
@@ -0,0 +1,69 @@
+#!/usr/bin/env bash
+#-------------------------------------------------------------------
+# test script for connection_life_time
+#
+source $TESTLIBS
+TESTDIR=testdir
+PSQL=$PGBIN/psql
+PG_CTL=$PGBIN/pg_ctl
+PGBENCH=$PGBIN/pgbench
+export PGDATABASE=test
+
+rm -fr $TESTDIR
+mkdir $TESTDIR
+cd $TESTDIR
+
+# create test environment.
+echo -n "creating test environment..."
+$PGPOOL_SETUP || exit 1
+echo "done."
+
+dir=`pwd`
+
+source ./bashrc.ports
+
+timeout=5
+echo "connection_life_time = $timeout" >> etc/pgpool.conf
+
+./startall
+
+export PGPORT=$PGPOOL_PORT
+
+wait_for_pgpool_startup
+
+# get backend pid
+pid=`$PSQL -t -p 11000 -c "select pg_backend_pid()" test`
+echo "backend pid is: $pid"
+sleep `expr $timeout + 1`
+ps $pid
+if [ $? = 0 ];then
+ echo "backend pid $pid still exists"
+ ./shutdownall
+ exit 1
+fi
+
+echo "ok with primary node = 0"
+
+# swap node 0 and node 1
+pg_ctl -D data0 -m f stop
+
+wait_for_pgpool_startup
+
+pcp_recovery_node -p $PCP_PORT -w 0
+
+wait_for_pgpool_startup
+
+# get backend pid
+pid=`$PSQL -t -p 11000 -c "select pg_backend_pid()" test`
+echo "backend pid is: $pid"
+sleep `expr $timeout + 1`
+ps $pid
+if [ $? = 0 ];then
+ echo "backend pid $pid still exists"
+ ./shutdownall
+ exit 1
+fi
+
+./shutdownall
+
+exit 0
[parent: a840ecb2c0aa]