mirror of
https://github.com/osukey/osukey.git
synced 2025-08-07 00:23:59 +09:00
Ensure blocking restoration only completes after update callback work is completed
This commit is contained in:
@ -923,13 +923,34 @@ namespace osu.Game.Database
|
|||||||
Logger.Log(@"Restoring realm operations.", LoggingTarget.Database);
|
Logger.Log(@"Restoring realm operations.", LoggingTarget.Database);
|
||||||
realmRetrievalLock.Release();
|
realmRetrievalLock.Release();
|
||||||
|
|
||||||
|
if (syncContext == null) return;
|
||||||
|
|
||||||
|
ManualResetEventSlim updateRealmReestablished = new ManualResetEventSlim();
|
||||||
|
|
||||||
// Post back to the update thread to revive any subscriptions.
|
// Post back to the update thread to revive any subscriptions.
|
||||||
// In the case we are on the update thread, let's also require this to run synchronously.
|
// In the case we are on the update thread, let's also require this to run synchronously.
|
||||||
// This requirement is mostly due to test coverage, but shouldn't cause any harm.
|
// This requirement is mostly due to test coverage, but shouldn't cause any harm.
|
||||||
if (ThreadSafety.IsUpdateThread)
|
if (ThreadSafety.IsUpdateThread)
|
||||||
syncContext?.Send(_ => ensureUpdateRealm(), null);
|
{
|
||||||
|
syncContext.Send(_ =>
|
||||||
|
{
|
||||||
|
ensureUpdateRealm();
|
||||||
|
updateRealmReestablished.Set();
|
||||||
|
}, null);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
syncContext?.Post(_ => ensureUpdateRealm(), null);
|
{
|
||||||
|
syncContext.Post(_ =>
|
||||||
|
{
|
||||||
|
ensureUpdateRealm();
|
||||||
|
updateRealmReestablished.Set();
|
||||||
|
}, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for the post to complete to ensure a second `Migrate` operation doesn't start in the mean time.
|
||||||
|
// This is important to ensure `ensureUpdateRealm` is run before another blocking migration operation starts.
|
||||||
|
if (!updateRealmReestablished.Wait(10000))
|
||||||
|
throw new TimeoutException(@"Reestablishing update realm after block took too long");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user