| From: | Narayanan Venkateswaran <narayananvpostgres(at)gmail(dot)com> |
|---|---|
| To: | Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> |
| Cc: | houzhijie22(at)gmail(dot)com, alvherre(at)kurilemu(dot)de, kuroda(dot)hayato(at)fujitsu(dot)com, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Fix LogStandbySnapshot() race during logical decoding activation |
| Date: | 2026-12-01 16:18:51 |
| Message-ID: | CAFjuD9fAsPQsp8c7v055Qu8gj+CQCkw4JpopY_P1KT7w1OkT+Q@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Masahiko, Zhijie,
> I've pushed the v5 patch.
The new Assert in LogStandbySnapshot() runs while XidGenLock is still held:
/* 1. standby.c: LogStandbySnapshot() (when xlog_logical_info is false) */
Assert(xlog_logical_info || !IsLogicalDecodingEnabled()); /* takes
LogicalDecodingControlLock */
...
LWLockRelease(XidGenLock);
That reverses the lock order used elsewhere and can deadlock on
--enable-cassert builds:
/* 2. logicalctl.c: DisableLogicalDecoding() */
LWLockAcquire(LogicalDecodingControlLock, LW_EXCLUSIVE);
... CheckLogicalSlotExists() /* takes
ReplicationSlotControlLock */
/* 3. launcher.c: reset_conflict_slot_xmin_to_safe_horizon() */
LWLockAcquire(ReplicationSlotControlLock, LW_EXCLUSIVE);
LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
/* 4. procarray.c: ProcArrayAdd() */
LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
LWLockAcquire(XidGenLock, LW_EXCLUSIVE);
I reproduced this deadlock locally on master with --enable-cassert.
we can just move the Assert right after LWLockRelease(XidGenLock);
Attached a patch for this in the email.
With that change, the deadlock goes away and 051_effective_wal_level.pl
still passes.
t/051_effective_wal_level.pl .. ok
All tests successful.
Files=1, Tests=50, 14 wallclock secs ( 0.04 usr 0.02 sys + 1.09 cusr
5.44 csys = 6.59 CPU)
Result: PASS
Should we fix this on master and REL_19_STABLE?
Thank you,
Narayanan
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Fix-lock-ordering-in-LogStandbySnapshot-Assert.patch | application/octet-stream | 2.2 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Greg Burd | 2026-12-01 16:41:09 | Re: Interrupts vs signals |
| Previous Message | Hüseyin Demir | 2026-12-01 16:16:11 | Re: [PATCH] Report changes discarded for relations not in the subscription |