]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix race condition in TransactionGroupUpdateXidStatus().
authorAmit Kapila <akapila@postgresql.org>
Mon, 28 Jun 2021 03:39:42 +0000 (09:09 +0530)
committerAmit Kapila <akapila@postgresql.org>
Mon, 28 Jun 2021 03:39:42 +0000 (09:09 +0530)
When we cannot immediately acquire CLogControlLock in exclusive mode at
commit time, we add ourselves to a list of processes that need their XIDs
status update. We do this if the clog page where we need to update the
current transaction status is the same as the group leader's clog page,
otherwise, we allow the caller to clear it by itself. Now, when we can't
add ourselves to any group, we were not clearing the current proc if it
has already become a member of some group which was leading to an
assertion failure when the same proc was assigned to another backend after
the current backend exits.

Reported-by: Alexander Lakhin
Bug: 17072
Author: Amit Kapila
Tested-By: Alexander Lakhin
Backpatch-through: 11, where it was introduced
Discussion: https://postgr.es/m/17072-2f8764857ef2c92a@postgresql.org

src/backend/access/transam/clog.c

index 26a6f5a389acbedef969c13e781511d8616e81c0..4f2baa0d3b9b3203e6c60acfd114cd7b751e6c03 100644 (file)
@@ -450,7 +450,12 @@ TransactionGroupUpdateXidStatus(TransactionId xid, XidStatus status,
                if (nextidx != INVALID_PGPROCNO &&
                        ProcGlobal->allProcs[nextidx].clogGroupMemberPage != proc->clogGroupMemberPage)
                {
+                       /*
+                        * Ensure that this proc is not a member of any clog group that
+                        * needs an XID status update.
+                        */
                        proc->clogGroupMember = false;
+                       pg_atomic_write_u32(&proc->clogGroupNext, INVALID_PGPROCNO);
                        return false;
                }