Re: Fix race condition in XLogLogicalInfo and ProcSignal initialization.

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fix race condition in XLogLogicalInfo and ProcSignal initialization.
Date: 2026-04-29 01:28:45
Message-ID: 512989C2-431E-4AE6-86B2-ED127C3DC439@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Apr 29, 2026, at 05:15, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> wrote:
>
> Hi all,
>
> I found a race condition issue between XLogLogicalInfo and ProcSignal
> initialization while reviewing another issue[1]. I'm starting a
> separate thread for the subject as it's not related to the issue
> reported on that thread.
>
> The issue is that child processes could miss the
> PROCSIGNAL_BARRIER_UPDATE_XLOG_LOGICAL_INFO signal during the
> initialization and end up in an inconsistent state because
> InitializeProcessXLogLogicalInfo() is called (in BaseInit()) before
> ProcSignalInit(). If the startup emits the signal to a process who is
> between two steps, the process would not reflect the latest
> XLogLogicalInfo state. I think we should move
> InitializeProcessXLogLogicalInfo() after ProcSignalInit() like we do
> so for InitLocalDataChecksumState().

I think this is correct.

After moving InitializeProcessXLogLogicalInfo() out of BaseInit(), background worker processes (BackgroundWorkerMain) will no longer hold a valid value of XLogLogicalInfo, but I guess that is fine as those processes don’t call ProcSignalInit() anyway.

>
> I've attached the patch to fix this issue. Feedback is very welcome.
>

Just found a typo:

```
+ * These initialization intentionally happens afater initializing the
```

afater => after

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ajin Cherian 2026-04-29 01:42:23 Re: Fix race condition in pg_get_publication_tables with concurrent DROP TABLE
Previous Message Michael Paquier 2026-04-28 23:12:04 Re: Fix the error hint message and test for reset_shared with unknown stats type