Skip to content

Commit 5ad165d

Browse files
committed
Acquire spinlock when updating 2PC slot data during logical decoding creation
The creation of a logical decoding context in CreateDecodingContext() updates some data of its slot for two-phase transactions if enabled by the caller, but the code forgot to acquire a spinlock when updating these fields like any other code paths. This could lead to the read of inconsistent data. Oversight in a8fd13c. Author: Sawada Masahiko Discussion: https://postgr.es/m/CAD21AoAD8_fp47191LKuecjDd3DYhoQ4TaucFco1_TEr_jQ-Zw@mail.gmail.com Backpatch-through: 15
1 parent f0e6d6d commit 5ad165d

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/backend/replication/logical/logical.c

+2
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,10 @@ CreateDecodingContext(XLogRecPtr start_lsn,
555555
/* Mark slot to allow two_phase decoding if not already marked */
556556
if (ctx->twophase && !slot->data.two_phase)
557557
{
558+
SpinLockAcquire(&slot->mutex);
558559
slot->data.two_phase = true;
559560
slot->data.two_phase_at = start_lsn;
561+
SpinLockRelease(&slot->mutex);
560562
ReplicationSlotMarkDirty();
561563
ReplicationSlotSave();
562564
SnapBuildSetTwoPhaseAt(ctx->snapshot_builder, start_lsn);

0 commit comments

Comments
 (0)