We detected a bug in our code, that we assume that is related to a race condition, but we don't understand why is happening. We had the following code
private static async Task<bool> IsMigrationPending(DependencyContainer dependencies)
{
bool isMigrationPending = false;
await WithCacheLock(MyRedisKey, dependencies, async () =>
{
isMigrationPending = await MyFunction();
LogMessage($"isMigrationPending = {isMigrationPending}").wait();
return isMigrationPending;
});
return isMigrationPending;
}
Despite of MyFunction() returns true the method IsMigrationPeding, most of the times we invoke it returned false. Chanigng the code line LogMessage($"isMigrationPending = {isMigrationPending}").wait() to
Await LogMessage($"isMigrationPending = {isMigrationPending}")
Then it fixed the problem, returning the expected value. For us doesn't make sense that changing a wait to await fix our problem. We expect that wait will block the execution until isMigrationPending value is available, or our assumption is incorrect?