]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix race condition in XLogLogicalInfo and ProcSignal initialization.
authorMasahiko Sawada <msawada@postgresql.org>
Thu, 7 May 2026 17:09:42 +0000 (10:09 -0700)
committerMasahiko Sawada <msawada@postgresql.org>
Thu, 7 May 2026 17:09:42 +0000 (10:09 -0700)
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 changes propagated during the
startup sequence.

Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Matthias van de Meent <boekewurm+postgres@gmail.com>
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
src/backend/utils/init/postinit.c

index ba8c9add67ac12d81365051ef4c6c35043def9d9..9803a0ee2a14112e7f7f38e81c1a0395ddc7172a 100644 (file)
@@ -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
index ecf78b9a9860dc22e3c1bc12291db0692d8926bf..2460e550f96e286b32aa37bcb98450c732d13cf0 100644 (file)
@@ -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.