1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 16:27:26 +08:00

Fix a failed BlockAllOperations leaving update realm in unretrieved state

If the operation timed out on..

```csharp
   throw new TimeoutException(@"Took too long to acquire lock");
```

..from an update thread, it would not restore the update context.

The next call would then fail on the assert that ensures a non-null
context in such cases.

Can add test coverage if required.
This commit is contained in:
Dean Herbert 2022-01-24 20:52:27 +09:00
parent f30894840c
commit 6f4c337a56

View File

@ -595,8 +595,8 @@ namespace osu.Game.Database
{
if (updateRealm == null)
{
// null realm means the update thread has not yet retrieved its instance.
// we don't need to worry about reviving the update instance in this case, so don't bother with the SynchronizationContext.
// null context means the update thread has not yet retrieved its context.
// we don't need to worry about reviving the update context in this case, so don't bother with the SynchronizationContext.
Debug.Assert(!ThreadSafety.IsUpdateThread);
}
else
@ -639,18 +639,19 @@ namespace osu.Game.Database
}
catch
{
realmCreationLock.Release();
restoreOperation();
throw;
}
return new InvokeOnDisposal<RealmAccess>(this, factory =>
{
factory.realmCreationLock.Release();
Logger.Log(@"Restoring realm operations.", LoggingTarget.Database);
return new InvokeOnDisposal(restoreOperation);
void restoreOperation()
{
Logger.Log(@"Restoring realm operations.", LoggingTarget.Database);
realmCreationLock.Release();
// Post back to the update thread to revive any subscriptions.
syncContext?.Post(_ => ensureUpdateRealm(), null);
});
}
}
// https://github.com/realm/realm-dotnet/blob/32f4ebcc88b3e80a3b254412665340cd9f3bd6b5/Realm/Realm/Extensions/ReflectionExtensions.cs#L46