Fix connection_life_time does not work.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Tue, 11 Aug 2020 01:26:43 +0000 (10:26 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Tue, 11 Aug 2020 02:48:36 +0000 (11:48 +0900)
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
src/test/regression/tests/031.connection_life_time/test.sh [new file with mode: 0755]

index 49db8fd5d22619691a54241725a8d3d6525d4c28..cb1277b1b30bd9e2539e51fec9ece89974ad174e 100644 (file)
@@ -329,7 +329,11 @@ void 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 (executable)
index 0000000..b2cc46e
--- /dev/null
@@ -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