aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2024-10-21 09:49:21 +0300
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2024-10-21 09:49:38 +0300
commit520ec2474b392805ca4d7f29205e245ac70ea0e1 (patch)
tree42d2cf9f7ff47fbdddec027d719387c05c310374 /src
parentfbbcbdef23349a81efad2bf742c94e2dc6c28130 (diff)
downloadpostgresql-520ec2474b392805ca4d7f29205e245ac70ea0e1.tar.gz
postgresql-520ec2474b392805ca4d7f29205e245ac70ea0e1.zip
Fix race condition in committing a serializable transaction
The finished transaction list can contain XIDs that are older than the serializable global xmin. It's a short-lived state; ClearOldPredicateLocks() removes any such transactions from the list, and it's called whenever the global xmin advances. But if another backend calls SummarizeOldestCommittedSxact() in that window, it will call SerialAdd() on an XID that's older than the global xmin, or if there are no more transactions running, when global xmin is invalid. That trips the assertion in SerialAdd(). Fixes bug #18658 reported by Andrew Bille. Thanks to Alexander Lakhin for analysis. Backpatch to all versions. Discussion: https://www.postgresql.org/message-id/18658-7dab125ec688c70b%40postgresql.org
Diffstat (limited to 'src')
-rw-r--r--src/backend/storage/lmgr/predicate.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/backend/storage/lmgr/predicate.c b/src/backend/storage/lmgr/predicate.c
index 052b2489a8b..00934db77ce 100644
--- a/src/backend/storage/lmgr/predicate.c
+++ b/src/backend/storage/lmgr/predicate.c
@@ -918,12 +918,17 @@ SerialAdd(TransactionId xid, SerCommitSeqNo minConflictCommitSeqNo)
LWLockAcquire(SerialSLRULock, LW_EXCLUSIVE);
/*
- * If no serializable transactions are active, there shouldn't be anything
- * to push out to the SLRU. Hitting this assert would mean there's
- * something wrong with the earlier cleanup logic.
+ * If 'xid' is older than the global xmin (== tailXid), there's no need to
+ * store it, after all. This can happen if the oldest transaction holding
+ * back the global xmin just finished, making 'xid' uninteresting, but
+ * ClearOldPredicateLocks() has not yet run.
*/
tailXid = serialControl->tailXid;
- Assert(TransactionIdIsValid(tailXid));
+ if (!TransactionIdIsValid(tailXid) || TransactionIdPrecedes(xid, tailXid))
+ {
+ LWLockRelease(SerialSLRULock);
+ return;
+ }
/*
* If the SLRU is currently unused, zero out the whole active region from