From 019569149d28f78c90833bcc6164400c9d1edda5 Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Fri, 24 Apr 2026 10:36:55 -0700 Subject: [PATCH v3] Fix race condition in XLogLogicalInfo and ProcSignal initialization. Previously, InitializeProcessXLogLogicalInfo() was called before ProcSignalInit(). This created a window where a process could miss a signal barrier if it was issued between these two calls. As a result, the process could fail to update its local XLogLogicalInfo cache, leading to an inconsistent logical decoding state. This commit fixes this by moving InitializeProcessXLogLogicalInfo() after ProcSignalInit(). This ensures that the process is registered to participate in signal barriers before its state is initialized, preventing it from missing any state change propagated during the startup sequence. Reviewed-by: Chao Li Reviewed-by: Matthias van de Meent Discussion: https://postgr.es/m/CAD21AoBzdeSyLSSPM5E6ysN1r8qzp8u_BRmnLvuAp_S8QxS_fQ@mail.gmail.com Discussion: https://postgr.es/m/CAD21AoBj+zKvgw_Q8gjr4YbKccW_uMe3OFQ5+KT246FHUuNXSQ@mail.gmail.com --- src/backend/postmaster/auxprocess.c | 8 ++++++++ src/backend/utils/init/postinit.c | 13 ++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/backend/postmaster/auxprocess.c b/src/backend/postmaster/auxprocess.c index ba8c9add67a..9803a0ee2a1 100644 --- a/src/backend/postmaster/auxprocess.c +++ b/src/backend/postmaster/auxprocess.c @@ -98,6 +98,14 @@ AuxiliaryProcessMainCommon(void) RESUME_INTERRUPTS(); + /* + * Initialize the process-local logical info WAL logging state. + * + * This must be called after ProcSignalInit() so that the process can + * participate in procsignal-based barriers that update this state. + */ + InitializeProcessXLogLogicalInfo(); + /* * Auxiliary processes don't run transactions, but they may need a * resource owner anyway to manage buffer pins acquired outside diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index ecf78b9a986..2460e550f96 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -662,9 +662,6 @@ BaseInit(void) /* Initialize lock manager's local structs */ InitLockManagerAccess(); - /* Initialize logical info WAL logging state */ - InitializeProcessXLogLogicalInfo(); - /* * Initialize replication slots after pgstat. The exit hook might need to * drop ephemeral slots, which in turn triggers stats reporting. @@ -833,6 +830,16 @@ InitPostgres(const char *in_dbname, Oid dboid, before_shmem_exit(ShutdownXLOG, 0); } + /* + * Initialize the process-local logical info WAL logging state. + * + * This must be called after ProcSignalInit() so that the process can + * participate in procsignal-based barriers that update this state. + * Furthermore, in !IsUnderPostmaster cases, this must occur after + * StartupXLOG() where the shared state is first established. + */ + InitializeProcessXLogLogicalInfo(); + /* * Initialize the relation cache and the system catalog caches. Note that * no catalog access happens here; we only set up the hashtable structure. -- 2.54.0