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.
This commit is contained in:
Heikki Linnakangas
2024-05-19 21:07:29 +03:00
parent e1a9669d05
commit 8dc1c48605
4 changed files with 6 additions and 6 deletions

View File

@@ -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"]
}