From 8dc1c486055f272cd7a54a8f0abdc1725c08001f Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Sun, 19 May 2024 21:07:29 +0300 Subject: [PATCH] Fix race condition in XLogWaitForReplayOf() ConditionVariablePrepareToSleep has this comment on it: > * Caution: "before entering the loop" means you *must* test the exit > * condition between calling ConditionVariablePrepareToSleep and calling > * ConditionVariableSleep. If that is inconvenient, omit calling > * ConditionVariablePrepareToSleep. We were not obeying that: we did not test the exit condition correctly between the ConditionVariablePrepareToSleep and ConditionVariableSleep calls, because the test that we had in between them only checked the local 'replayRecPtr' variable, without updating it from shared memory. That wasn't too serious, because the loop includes a 10 second timeout, and would retry and succeed if the original update was missed. Still, better fix it. To fix, just remove the ConditionVariablePrepareToSleep() call. As the comment says, that's also correct, and even more efficient if we assume that sleeping is rare. --- vendor/postgres-v14 | 2 +- vendor/postgres-v15 | 2 +- vendor/postgres-v16 | 2 +- vendor/revisions.json | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/vendor/postgres-v14 b/vendor/postgres-v14 index d6f7e2c604..a6dc3f010d 160000 --- a/vendor/postgres-v14 +++ b/vendor/postgres-v14 @@ -1 +1 @@ -Subproject commit d6f7e2c604bfc7cbc4c46bcea0a8e800f4bc778a +Subproject commit a6dc3f010da31472a7ae9ab0ddfbf6e49131d93c diff --git a/vendor/postgres-v15 b/vendor/postgres-v15 index f0d6b0ef75..6fd679f515 160000 --- a/vendor/postgres-v15 +++ b/vendor/postgres-v15 @@ -1 +1 @@ -Subproject commit f0d6b0ef7581bd78011832e23d8420a7d2c8a83a +Subproject commit 6fd679f5154d12f4892ddd450cc6be28a8ac31b0 diff --git a/vendor/postgres-v16 b/vendor/postgres-v16 index 8ef3c33aa0..1f63dd206a 160000 --- a/vendor/postgres-v16 +++ b/vendor/postgres-v16 @@ -1 +1 @@ -Subproject commit 8ef3c33aa01631e17cb24a122776349fcc777b46 +Subproject commit 1f63dd206a8aaa4727baad334c548219c52878e1 diff --git a/vendor/revisions.json b/vendor/revisions.json index c5b55762fa..a66c7ffe25 100644 --- a/vendor/revisions.json +++ b/vendor/revisions.json @@ -1,5 +1,5 @@ { - "v16": ["16.2", "8ef3c33aa01631e17cb24a122776349fcc777b46"], - "v15": ["15.6", "f0d6b0ef7581bd78011832e23d8420a7d2c8a83a"], - "v14": ["14.11", "d6f7e2c604bfc7cbc4c46bcea0a8e800f4bc778a"] + "v16": ["16.2", "1f63dd206a8aaa4727baad334c548219c52878e1"], + "v15": ["15.6", "6fd679f5154d12f4892ddd450cc6be28a8ac31b0"], + "v14": ["14.11", "a6dc3f010da31472a7ae9ab0ddfbf6e49131d93c"] }