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 1wejUh-004yqG-2J for pgpool-hackers@arkaria.postgresql.org; Wed, 01 Jul 2026 01:12:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wejUg-00AsG6-25 for pgpool-hackers@arkaria.postgresql.org; Wed, 01 Jul 2026 01:12:02 +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 1wejUg-00AsE8-1I for pgpool-hackers@lists.postgresql.org; Wed, 01 Jul 2026 01:12:02 +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 1wejUe-0000000173F-0Gpp for pgpool-hackers@lists.postgresql.org; Wed, 01 Jul 2026 01:12:02 +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:From:Subject:To:Message-Id:Date:Sender:Reply-To:Cc:Content-ID: Content-Description:In-Reply-To:References; bh=7MpdaEcWS3vnnZDK9Fxgff/6sbvIwtpJLuzIN+XUA0M=; b=b5NEULgezA4D6aNeWRc905g+O1 CBTeYgBdPcxy4USmYEx8e1I6v280cfwBewM7ONsrVCtjCetbrRFaQfM07T1SRGy61p9RvmMS+tIYp rg5FNcTSh3LGMGdrAs+a82onZETjbYdILyhSdjihIctWHpW/pWHBMzmNJwEjA13cfe8PQZNhUo3Vj iyM/e4JGt7w1VIuorpCKidychvLkP6onw9GdJnZswS/TJxTBGJ2YnbhJS6YYyXUQ5wE70qrZh4sy9 x1zaZtdM2qDQyEI3W5FnQP5n/RHoITi+ggAZITxgt2k1FygDTNNhDN89iv4qyJVJPyzVQ5CxcHNub gV+LpwaA==; Received: from [2409:11:4120:300:b971:c97:168c:d41e] (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 1wejUb-008NnS-1C for pgpool-hackers@lists.postgresql.org; Wed, 01 Jul 2026 01:11:59 +0000 Date: Wed, 01 Jul 2026 10:11:48 +0900 (JST) Message-Id: <20260701.101148.451717746326656928.ishii@postgresql.org> To: pgpool-hackers@lists.postgresql.org Subject: Adding volatile qualifer From: Tatsuo Ishii X-Mailer: Mew version 6.8 on Emacs 29.3 Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Wed_Jul__1_10_11_48_2026_192)--" Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2409:11:4120:300:b971:c97:168c:d41e (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ----Next_Part(Wed_Jul__1_10_11_48_2026_192)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit While looking into the Pgpool-II main source code, I noticed that local pointer array "my_backend_status" is not volatile qualified, while it should have been. BACKEND_STATUS *my_backend_status[MAX_NUM_BACKENDS]; /* Backend status buffer */ This array members are initialized: for (i = 0; i < MAX_NUM_BACKENDS; i++) { my_backend_status[i] = &(BACKEND_INFO(i).backend_status); } Without volatile, *(my_backend_status[i]) could read state value because of compiler optimization. Since my_backend_status[i] is referred to in popular VALID_BACKEND macro, we should fix it in all supported branches. Attached is the patch for master branch. Regards, -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp ----Next_Part(Wed_Jul__1_10_11_48_2026_192)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="failover_fix.patch" diff --git a/src/include/pool.h b/src/include/pool.h index 549aed30f..ef0876c84 100644 --- a/src/include/pool.h +++ b/src/include/pool.h @@ -345,7 +345,7 @@ extern int pool_get_major_version(void); extern bool pool_is_node_to_be_sent_in_current_query(int node_id); extern int pool_virtual_main_db_node_id(void); -extern BACKEND_STATUS *my_backend_status[]; +extern volatile BACKEND_STATUS *my_backend_status[]; extern int my_main_node_id; #define VALID_BACKEND(backend_id) \ diff --git a/src/main/pgpool_main.c b/src/main/pgpool_main.c index 19d89cb79..ab8946228 100644 --- a/src/main/pgpool_main.c +++ b/src/main/pgpool_main.c @@ -277,7 +277,9 @@ static pid_t pgpool_logger_pid = 0; /* pid for pgpool_logger process */ static pid_t wd_lifecheck_pid = 0; /* pid for child process handling watchdog * lifecheck */ -BACKEND_STATUS *my_backend_status[MAX_NUM_BACKENDS]; /* Backend status buffer */ +/* Backend status buffer */ +volatile BACKEND_STATUS *my_backend_status[MAX_NUM_BACKENDS]; + int my_main_node_id; /* Main node id buffer */ /* ----Next_Part(Wed_Jul__1_10_11_48_2026_192)----