RE: Fix "unexpected logical decoding status change" error; from concurrent logical decoding activation

From: "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>
To: 'Masahiko Sawada' <sawada(dot)mshk(at)gmail(dot)com>
Cc: Alexander Lakhin <exclusion(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Srinath Reddy Sadipiralla <srinath2133(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: RE: Fix "unexpected logical decoding status change" error; from concurrent logical decoding activation
Date: 2026-11-02 04:47:36
Message-ID: OS7PR01MB1831787EC9E31EB5821B4CCCBF56A2@OS7PR01MB18317.jpnprd01.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Sawada-san,

> I've reviewed only the 0001 patch. While I agree with your analysis,

Thanks!

> I
> think it's sufficient to call injection_points_detach() before quit,
> no?

That's not enough. As I posted in the previous post, exiting backend which calls
_set_local can cleanup injection points registered by other backends.
Here below scenario can still happen:

0. assuming that there is a background psql session, and the related backend (b1)
does _set_local() and _attach() for an injection point "logical-decoding-activation".
b1 has been storing the name in inj_list_local.
1. a backend (b2) calls _detach(). An injection point is removed from the shared hash.
2. the background psql session quits, the b1 starts exiting (and delayed).
3. another backend (b3) calls _set_local() and _attach() for the same injection
point "logical-decoding-activation". It's registered on the shared hash.
4. b1 reaches the cleanup function and removes "logical-decoding-activation"
from the shared hash.
5. b3 calls pg_create_logical_replication_slot(). Since the injection point has
already been removed it won't wait anymore.
6. upcoming wait_for_event() stucks since nobody waits there.

I confirmed that the test could still fail by adding detach() before the quit atop the reproducer.

Alternative fix idea is to ensure the backend process exits, v2 implements the same.
If we want to use _detach() approach we need to fix race condition for injection
ponits side.

> Also, the following codes in 051_effective_wal_level.pl seems to
> have the same issue;

Right, fixed.

[1]: https://www.postgresql.org/message-id/OS7PR01MB183172A425382C8A781DB153FF56D2%40OS7PR01MB18317.jpnprd01.prod.outlook.com

Best regards,
Hayato Kuroda
FUJITSU LIMITED

Attachment Content-Type Size
v2-0001-Stabilize-051_effective_wal_level.patch application/octet-stream 6.1 KB
v2-0002-Ensure-injection-point-repack-concurrently-before.patch application/octet-stream 1.3 KB
v2-0003-Stabilize-010_index_concurrently_upsert.patch application/octet-stream 6.1 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message surya poondla 2026-11-02 04:49:13 Re: Wrong LSN in WAL decoding error messages
Previous Message Koshino Taiki 2026-11-02 04:40:25 Re: Proposal: Include CHECK constraint expression in violation error DETAIL