]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Acquire spinlock when updating 2PC slot data during logical decoding creation
authorMichael Paquier <michael@paquier.xyz>
Thu, 12 Jan 2023 04:41:22 +0000 (13:41 +0900)
committerMichael Paquier <michael@paquier.xyz>
Thu, 12 Jan 2023 04:41:22 +0000 (13:41 +0900)
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

src/backend/replication/logical/logical.c

index 625a7f42730d131619d8df80bb234b1ac205ac76..466f30c22d91a8ba99558dd937bdc0e21950e273 100644 (file)
@@ -555,8 +555,10 @@ CreateDecodingContext(XLogRecPtr start_lsn,
        /* Mark slot to allow two_phase decoding if not already marked */
        if (ctx->twophase && !slot->data.two_phase)
        {
+               SpinLockAcquire(&slot->mutex);
                slot->data.two_phase = true;
                slot->data.two_phase_at = start_lsn;
+               SpinLockRelease(&slot->mutex);
                ReplicationSlotMarkDirty();
                ReplicationSlotSave();
                SnapBuildSetTwoPhaseAt(ctx->snapshot_builder, start_lsn);