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 06:04:03 +0000 (15:04 +0900)
commita2f3ac6a0291b55651faf1c1ff42363598b26df6
tree5bc6b85d99fa58dd1ab5c14e1ded3a6cfeb5827a
parent09a3ae1d207b1eb70943b8f43c74702e22ff8b07
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