From: Tatsuo Ishii Date: Tue, 11 Aug 2020 01:26:43 +0000 (+0900) Subject: Fix connection_life_time does not work. X-Git-Tag: V3_7_15~18 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=b47a050be64183809f82a458e19eef73becf4475;p=pgpool2.git 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 --- diff --git a/src/protocol/pool_connection_pool.c b/src/protocol/pool_connection_pool.c index 49db8fd5d..cb1277b1b 100644 --- a/src/protocol/pool_connection_pool.c +++ b/src/protocol/pool_connection_pool.c @@ -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 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