Skip to content

Commit 9f2cc1a

Browse files
author
Amit Kapila
committed
Fix uninitialized access to InitialRunningXacts during decoding.
In commit 272248a, we introduced an InitialRunningXacts array to remember transactions and subtransactions that were running when the xl_running_xacts record that we decoded was written. This array was allocated in the snapshot builder memory context after we restore serialized snapshot but we forgot to reset the array while freeing the builder memory context. So, the next time when we start decoding in the same session where we don't restore any serialized snapshot, we ended up using the uninitialized array and that can lead to unpredictable behavior. This problem doesn't exist in HEAD as instead of using InitialRunningXacts, we added the list of transaction IDs and sub-transaction IDs, that have modified catalogs and are running during snapshot serialization, to the serialized snapshot (see commit 7f13ac8). Reported-by: Maxim Orlov Author: Masahiko Sawada Reviewed-by: Amit Kapila, Maxim Orlov Backpatch-through: 11 Discussion: https://postgr.es/m/CACG=ezZoz_KG+Ryh9MrU_g5e0HiVoHocEvqFF=NRrhrwKmEQJQ@mail.gmail.com
1 parent 8e7c867 commit 9f2cc1a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/backend/replication/logical/snapbuild.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ AllocateSnapshotBuilder(ReorderBuffer *reorder,
343343

344344
MemoryContextSwitchTo(oldcontext);
345345

346+
/* The initial running transactions array must be empty. */
347+
Assert(NInitialRunningXacts == 0 && InitialRunningXacts == NULL);
348+
346349
return builder;
347350
}
348351

@@ -363,6 +366,10 @@ FreeSnapshotBuilder(SnapBuild *builder)
363366

364367
/* other resources are deallocated via memory context reset */
365368
MemoryContextDelete(context);
369+
370+
/* InitialRunningXacts is freed along with the context */
371+
NInitialRunningXacts = 0;
372+
InitialRunningXacts = NULL;
366373
}
367374

368375
/*

0 commit comments

Comments
 (0)