[pgpool-committers: 4916] pgpool: Fix pgpool child process segfault when ALWAYS_MASTER is on.

Tatsuo Ishii ishii at postgresql.org
Tue Aug 7 21:43:28 JST 2018


Fix pgpool child process segfault when ALWAYS_MASTER is on.

If following conditions are all met pgpool child segfaults:

1) Streaming replication mode.

2) fail_over_on_backend_error is off.

3) ALWAYS_MASTER flag is set to the master (writer) node.

4) pgpool_status file indicates that the node mentioned in #3 is in
   down status.

What happens here is,

1) find_primary_node() returns node id 0 without checking the status
   of node 0 since ALWAYS_MASTER is set. It's remembered as the
   primary node id. The node id is stored in Req_info->primary_node_id.

2) The connection to backend 0 is not created since pgpool_status says
   it's in down status.

3) upon starting of session, select_load_balancing_node () is called
   and it tries to determine the database name from client's start up
   packet.

4) Since MASTER_CONNECTION macro points to the PRIMARY_NODE,
   MASTER_CONNECTION(ses->backend) is NULL and it results in a segfault.

The fix is, to change PRIMARY_NODE_ID macro so that it returns
REAL_MASTER_NODE_ID (that is the youngest node id which is alive) if
the node id in Req_info->primary_node_id is in down status. This can
be checked using VALID_BACKEND_RAW macro.

VALID_BACKEND macro cannot be used here because it calls
pool_is_node_to_be_sent_in_current_query() inside. Problem is, when a
query is about to processed, pool_is_query_in_progress() is already
set but pool_is_node_to_be_sent() could return false because
where_to_send member in the query context may not be is set yet
(that's the cause of the enbug in Pgpool-II 3.7.2).

So we have the "true" primary node id in Req_info->primary_node_id,
and "fake" primary node id returned by PRIMARY_NODE_ID macro.

See [pgpool-hackers: 2687] and [pgpool-general: 5881] Pgpool-3.7.1
segmentation fault for more details.

Since ALWAYS_MASTER flag was introduced in 3.7, back pached to 3.7
only.
Per bug report from Philip Champon.

Branches
--------
SCRAM_AUTH
master
query_cache

Details
-------
https://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=6e7a68c1c73d8a9a7847ab73cb3cecdfbed0f90c

Modified Files
--------------
src/include/pool.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)



More information about the pgpool-committers mailing list