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 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
This commit is contained in:
Masahiko Sawada 2026-05-07 10:09:42 -07:00
parent ecb2508aaf
commit b384cdb274
2 changed files with 18 additions and 3 deletions

View 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

View 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.