pgpool: Prevent pcp_node_info from hanging.

From: Tatsuo Ishii <ishii(at)postgresql(dot)org>
To: pgpool-committers(at)lists(dot)postgresql(dot)org
Subject: pgpool: Prevent pcp_node_info from hanging.
Date: 2026-06-07 03:12:09
Message-ID: E1wW3vl-007ANh-1Y@gothos.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgpool-committers

Prevent pcp_node_info from hanging.

The problem:
In inform_node_info() (src/pcp_con/pcp_worker.c), the PCP reply packet
reads bi->replication_state and bi->replication_sync_state directly
from shared memory twice: once via strlen() to compute the packet
length, and once via pcp_write() to write the payload.

The streaming-replication check worker rewrites those same
shared-memory strings without a lock (it clears them to "" then
repopulates them every check cycle and on state transitions,
src/streaming_replication/pool_worker_child.c). If the string's length
changes between the two reads, the declared wsize no longer matches
the bytes actually written, so the PCP byte stream desynchronises. The
client then blocks forever in pcp_read() waiting for bytes the server
never sends.

The fix:
Snapshot the two strings into local buffers once, right after bi =
pool_get_node_info(i), and use the locals for both the length and the
payload — so a single packet is always internally consistent. This
matches how every other field in the packet is already handled.

Author: Emond Papegaaij <emond(dot)papegaaij(at)gmail(dot)com>
Reviewed-by: Tatsuo Ishii <ishii(at)postgresql(dot)org>
Discussion: https://www.postgresql.org/message-id/CAGXsc%2BZhGjwm%2BF42Xmt8Qn1qP_h7woipiV0WsY-e-P7W3ZG2OA%40mail.gmail.com
Backpatch-through: v4.3

Branch
------
V4_3_STABLE

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

Modified Files
--------------
src/pcp_con/pcp_worker.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)

Browse pgpool-committers by date

  From Date Subject
Next Message Tatsuo Ishii 2026-06-07 03:12:15 pgpool: Prevent pcp_node_info from hanging.
Previous Message Tatsuo Ishii 2026-06-05 04:44:05 pgpool: Fix typo in in read_kind_from_backend() comment.