1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 10:52:53 +08:00

Fix thread safety of OnlineMetadataClient.UserStates

Closes https://github.com/ppy/osu-framework/issues/6081.
This commit is contained in:
Dean Herbert 2023-12-20 14:08:12 +09:00
parent ff6a02be82
commit 856c59f7f7
No known key found for this signature in database

View File

@ -97,8 +97,11 @@ namespace osu.Game.Online.Metadata
{
if (!connected.NewValue)
{
isWatchingUserPresence.Value = false;
userStates.Clear();
Schedule(() =>
{
isWatchingUserPresence.Value = false;
userStates.Clear();
});
return;
}
@ -187,13 +190,13 @@ namespace osu.Game.Online.Metadata
public override Task UserPresenceUpdated(int userId, UserPresence? presence)
{
lock (userStates)
Schedule(() =>
{
if (presence != null)
userStates[userId] = presence.Value;
else
userStates.Remove(userId);
}
});
return Task.CompletedTask;
}
@ -215,8 +218,8 @@ namespace osu.Game.Online.Metadata
if (connector?.IsConnected.Value != true)
throw new OperationCanceledException();
// must happen synchronously before any remote calls to avoid misordering.
userStates.Clear();
// must happen synchronously before any remote calls to avoid mis-ordering.
Schedule(() => userStates.Clear());
Debug.Assert(connection != null);
await connection.InvokeAsync(nameof(IMetadataServer.EndWatchingUserPresence)).ConfigureAwait(false);
}