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 1wfDbu-005KzR-1J for pgpool-hackers@arkaria.postgresql.org; Thu, 02 Jul 2026 09:21:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wfDbt-001AE5-0l for pgpool-hackers@arkaria.postgresql.org; Thu, 02 Jul 2026 09:21:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wfDbs-001ADx-34 for pgpool-hackers@lists.postgresql.org; Thu, 02 Jul 2026 09:21:29 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wfDbq-00000001DRM-3KKa for pgpool-hackers@lists.postgresql.org; Thu, 02 Jul 2026 09:21:27 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-2c82538b6b0so12187835ad.1 for ; Thu, 02 Jul 2026 02:21:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1782984085; cv=none; d=google.com; s=arc-20260327; b=eyZmvl8pyiShGTEoLnwYaDoez22SAAoJf40INKLxxOMMcwN/Axo80DABvSDnj1OTVa Yj43KiyijgxlmQbUCnb74O1I7qvEkAtVm0CGYXLQJkyIiTbuuuKop4Oh5Q7mbjFB+mDe 9RE57HCtymz6uXcjxjnFjK+8EqeoYB9Q9ISjr54VOTU65KqBB5TVMMVeW4vECbYON78l bN8TtQ55nWJPWDjnEwNIKDX6SPQ9IGGNsMEXiA2Vf76UQUBlOZ5WCGWgDr7nqvE2JppU yZji5brDMLbBgPsaETZqURh9Wpko5QLGQeqSD71EP/hHtTL5Tj//eogXWoPY6y3ltFB2 nd+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=vuihEqzqy8YGtq/uFinKEcHkDagVfwB8Hdx/4tvECY0=; fh=m3oiE62fRN5J1XaE+5vpHZRIgCyFefxVI0mFw3d8yxA=; b=BttxdBbYOqYp7rCGkPTTc+sZyAvdERBgXtrrG2iaeNmi0L57Orvzj9csqJmH/IyUTM tiwfvvjKCT8saPd1X9XMsHryddiMpUrFc7C8OoED3pmbjnc60cN/27sgtkmFYVd1mhom hodK6qqJdc7Oth8IcGL3XHfxZFK2aWzW6dtbm+NOlDJLhG/Lg62wMb8kYDMYXQSlh6LX gDIlvAl+BFPTjYdeYAV/rZXBFG+dGlZUccAJqoMKr2EWtndmBuVXkkW/Rh7CSuFlr9Rs 2ria2FO9iP+urTxcV6heQU4zVUVFacmB5TqtoQfd188iEnSPHZXSGFuBZis/V4xSY4mT qMqw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782984085; x=1783588885; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=vuihEqzqy8YGtq/uFinKEcHkDagVfwB8Hdx/4tvECY0=; b=ASka9NndhIOBGP6hIbESHrnkwawefIRV7tNgYfDmf0LFSIFDNHcEhWPak7hPHCuN6S q2cGaxogq4Rn63Fznu5smOfys++E2bgwoU0THkZlNWzrJiQpCL4FAkeb5VePIrURJVp/ xBYYHLiU6MtK3mB+kemCcQtLYVGkSQW5e3caiMJqikL1dLx/p0y9VFJQ0IlCjzvan5Ze m/57fan+3Zz4JPjGD3NKNsNAJu3QmuMSeK7H8sYUf7HsAd5SzOwxbFtcvA6FE3LbsMcI zMMTraY2j3rzzH/IC3DLXI59nVgaOIySv6nxTEJq7d2JMUBfN7Z+okvWH6z6Sdzc0lRQ EBYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782984085; x=1783588885; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=vuihEqzqy8YGtq/uFinKEcHkDagVfwB8Hdx/4tvECY0=; b=emyYMXOgy4NyBg1+xXuGjX/XUCTRQ9DOgpR/NytTZitrAK32mW691eNee7Moi8lq2w TiETniXnoTVmCgypeZjDi0MQhmvSi3h+5ZDq+w/i7pvI7UJELDJ8zLiIE/jwOA/IjeIw 7iiJre/Mo6u68/IpzWPu0HFZUs/PIUvvcxd/n5DssBgjgHVwZZBIFjc59hVko+qu/x7V VNk4A4V4hA615NmlOyoy5j38k+bSMVGDMVbk6vhDP3PgT6jlwTOe015h0WW4XxxhhrSM +W6w4P+o71EPP8PZo9WlB4ilGap/8C5kMMnmoJtRcMdDcEAWZPgWxSo//pvQ8RiTuyZ1 iyYg== X-Gm-Message-State: AOJu0Yz0wg/E326d6y1t/HTBS9SCCNMiqTsU1VNQN5n4UCpDkNPhs5zj up/tMH0SCwEevFFnt9Oad0/K7W4Gp98CnNZolAsZsQ2dtUbANMZYNGzhOzuu8YLE8gmho0QahLk KSnpHjdBUR/bT2WgfiUJEo2hkdOHtmJ6bJh7piA4= X-Gm-Gg: AfdE7cmEkx4xKTvEn2knpIgoinxd1g4FW5pBJlpBDkB4lDCRoSMgwpCa1weIkC66PxI 0/gldjQTjzT/tQ0zE0/pJ06B+pKV5IIJoufzNJ97Wdjs1GII+hh20wiYKOej4+9uuIIOwZimqSi kkbs5f4NGfAMoCUSW2mDZll/GSCFRqX8RY1e/7prp3FYoZynqJkQMUfzFg6RJQ77UDrjyaeOQOB +3Jw8eYDYZwB4Fvwlz9eUHAKl+A5uXeEDa1Kfq0XXlS7rAV0jCoddZKhyoysOE5B1H4ask7XGVM lrpL3LIk21qqCtz/gwxyGxKzzI7q8w== X-Received: by 2002:a17:902:f601:b0:2c0:e5ee:f56c with SMTP id d9443c01a7336-2ca7e73883emr58557765ad.20.1782984085227; Thu, 02 Jul 2026 02:21:25 -0700 (PDT) MIME-Version: 1.0 References: <20260702.163922.30147080599128209.ishii@postgresql.org> In-Reply-To: <20260702.163922.30147080599128209.ishii@postgresql.org> From: Emond Papegaaij Date: Thu, 2 Jul 2026 11:21:13 +0200 X-Gm-Features: AVVi8CfBal7tKQ6xK-MXrCaXsFgngcRvtp2ABkX4BmApRQK_ZfCxL13Wa41rKu4 Message-ID: Subject: Re: [PATCH] Segfault in pool_do_auth() when failover races with a new connection To: Tatsuo Ishii Cc: pgpool-hackers@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, The new patch looks fine to me. There's however one thing Claude pointed out. According to it, my_main_node_id, private_backend_status[], and my_backend_status[] are per-process globals (copied on fork), not shared memory. So, making any of those volatile should not make any difference. Best regards, Emond Op do 2 jul 2026 om 09:39 schreef Tatsuo Ishii : > > Hi Emond, > > > Hi, > > > > Last night one of CI builds detected a segmentation fault in pgpool > > (4.7.2). I've ran an analysis on the coredump with Claude and came to > > the conclusion that this can happen when trying to open a connection > > in the middle of a failover. > > > > Symptom / backtrace (resolved from the core dump): > > pool_do_auth (src/auth/pool_auth.c:349) <-- SIGSEGV, fault addr 0x0 > > connect_backend (src/protocol/child.c:1099) (PG_TRY block) > > get_backend_connection (src/protocol/child.c:2109) > > do_child (src/protocol/child.c:233) > > > > The crashing statement is: > > protoMajor =3D MAIN_CONNECTION(cp)->sp->major; /* pool_auth.c:349 */ > > i.e. cp->slots[MAIN_NODE_ID] is NULL. From the core, the pool had > > slots[0] =3D=3D NULL while slots[1]/slots[2] were valid, and MAIN_NODE_= ID =3D=3D 0. > > > > pool_initialize_private_backend_status() snapshots > > private_backend_status[] and my_main_node_id non=E2=80=91atomically w.r= .t. the > > parent's failover, so a child can capture my_main_node_id =3D=3D 0 whil= e > > node 0 is already CON_DOWN. new_connection() then never creates > > slots[0], and pool_do_auth() dereferences the NULL main slot. (Same > > class as the NULL=E2=80=91MAIN_CONNECTION case noted in > > pool_virtual_main_db_node_id().) > > From pool_initialize_private_backend_status(): > > for (i =3D 0; i < MAX_NUM_BACKENDS; i++) > { > private_backend_status[i] =3D BACKEND_INFO(i).backend_sta= tus; > /* my_backend_status is referred to by VALID_BACKEND macr= o. */ > my_backend_status[i] =3D &private_backend_status[i]; > } > > my_main_node_id =3D REAL_MAIN_NODE_ID; > > BACKEND_INFO(i).backend_status are updated in the pgpool main process > at line 1793 of failover(pgpool_main.c) by calling > handle_failover_request(), but REAL_MAIN_NODE_ID (actually > Req_info->main_node_id, shared memory) is updated at 1846 of > failover() by calling save_node_info(). So updating REAL_MAIN_NODE_ID > tends to slightly delay after updating > BACKEND_INFO(i).backend_status. This may explain why my_main_node is > set the stale data (1). > > Another possibility is my_main_node_id being lacking volatile > qualification. This also could set stale data to my_main_node_id (2). > > Of course (1) and (2) are not mutually exclusive. So your patch for > (1) and fix for (2) need to be both applied. > > By the way in your patch there is loops like this. This can be > replaced by existing get_next_main_node(). > > + for (i =3D 0; i < NUM_BACKENDS; i++) > + { > + if (private_backend_status[i] =3D=3D CON_UP || > + private_backend_status[i] =3D=3D CON_CONN= ECT_WAIT) > + { > + my_main_node_id =3D i; > + break; > + } > + } > > All of the above in mind, I propose attached patch. > > What do you think? > -- > Tatsuo Ishii > SRA OSS K.K. > English: http://www.sraoss.co.jp/index_en/ > Japanese:http://www.sraoss.co.jp