Fix segfault when node 0 is in down status.
authorTatsuo Ishii <ishii@postgresql.org>
Sun, 5 Aug 2018 01:54:18 +0000 (10:54 +0900)
committerTatsuo Ishii <ishii@postgresql.org>
Sun, 5 Aug 2018 02:00:00 +0000 (11:00 +0900)
commite8643465be0d53356fee7b729b91ee93d56562f7
tree4e6854679e695d7b39d28626cfee8f6fa2c978f8
parent036e2159b7948bbebe6a55207ef8bc75d340de1c
Fix segfault when node 0 is in down status.

MASTER_CONNECTION refers to the connection to "master"
node. "Master" means the first live backend appearing in
pgpool.conf. The master node is determined at the time of fail over.
Unfortunately with both health check and fail_over_on_backend_error
are disabled, there's no chance of failover, which means the master
node id is remained the default value 0. So the MASTER_CONNECTION
refers to the node 0, and the connection is NULL.

Fix is as follows.

If attempt to connection to backend fails, check the master node id in
the shared memory.  If the master node id is the failed node, then
look for new master node using get_next_master_node (this was a static
function, but now it's made to public) and set the node id to the
master node id in the shared memory area.

Problem reported by Muhammad Usama in [pgpool-hackers: 2905].
src/include/pool.h
src/main/pgpool_main.c
src/protocol/pool_connection_pool.c