Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wVHC9-001qHk-10 for pgpool-hackers@arkaria.postgresql.org; Thu, 04 Jun 2026 23:09:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wVHC7-009EZ8-2q for pgpool-hackers@arkaria.postgresql.org; Thu, 04 Jun 2026 23:09:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wVHC7-009EYz-1n for pgpool-hackers@lists.postgresql.org; Thu, 04 Jun 2026 23:09:47 +0000 Received: from meldrar.postgresql.org ([2a02:c0:301:0:ffff::31]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wVHC2-00000001Jpt-1Gbv for pgpool-hackers@lists.postgresql.org; Thu, 04 Jun 2026 23:09:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Content-Transfer-Encoding:Content-Type: Mime-Version:References:In-Reply-To:From:Subject:Cc:To:Message-Id:Date:Sender :Reply-To:Content-ID:Content-Description; bh=ShU0GY+eaI/qEy61SUeEaG0iwoPI5StOIVxl8k6A4hE=; b=1A77K+fJiUb55x515tD9GeUM1r rCS4NhjZRAM9a2pruCyJQXpm6sJXG2ZWD79Ws+fK8Sz4byuSffk91HolTBmth7T7TUEau/mY6N8Pm 2hJF5wtF4kYDlo34CC3Jk2aIU+DS42XK/fu4NArKX9JLGJ7lHH7PwSBMpLzOiNMwJ0DFVmhMnYaVK QrBpjWWUBnkfeJVniCCKr6Xt2YR8cEfFuByNUE78pR/dB5l0nKblng8Jtaw8RgsYNO7/YlYS8sUTm RP5f2DaH/kbGVUkB+AXxQ8qQG32lZYDqliWQ4lLf7Z896tuTBpWwjcHyUGCLj2kAdJR0+gCFivGQA scFbmneA==; Received: from [2409:11:4120:300:d43c:ca28:c007:4f2d] (helo=localhost) by meldrar.postgresql.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wVHBx-003DQH-1r; Thu, 04 Jun 2026 23:09:42 +0000 Date: Fri, 05 Jun 2026 08:09:32 +0900 (JST) Message-Id: <20260605.080932.2120655380457259936.ishii@postgresql.org> To: emond.papegaaij@gmail.com Cc: pgpool-hackers@lists.postgresql.org Subject: Re: Race condition in pcp_node_info can cause it to hang From: Tatsuo Ishii In-Reply-To: References: X-Mailer: Mew version 6.8 on Emacs 29.3 Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2409:11:4120:300:d43c:ca28:c007:4f2d (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Emond, > Hi, > > We've hit another very rare flake in our tests, which can cause > pcp_node_info to hang indefinitely. I've analyzed the problem with > Claude Code, and it came to the conclusion and (quite small) fix > below. Attached is a patch against 4.7. > > 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. Thank you for the report and fix. Yes, I agree there's a race condition between sr checker process and pcp_node_info. I think introducing a lock to protect bi->replication_state and bi->replication_sync_state is overkill. The suggested fix seems to be a right direction. Will push after current release freeze is over (supposed to be finished by the end of today). Regards, -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp