mirror of
https://github.com/ppy/osu.git
synced 2025-01-19 06:32:55 +08:00
Merge pull request #16673 from peppy/fix-polling-component-thread-safety
Fix occasional non-fatal errors from polling API requests incorrectly getting queued twice
This commit is contained in:
commit
c7f8528d63
@ -2,8 +2,10 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Development;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Threading;
|
using osu.Framework.Threading;
|
||||||
|
|
||||||
@ -66,6 +68,8 @@ namespace osu.Game.Online
|
|||||||
|
|
||||||
private void doPoll()
|
private void doPoll()
|
||||||
{
|
{
|
||||||
|
Debug.Assert(ThreadSafety.IsUpdateThread);
|
||||||
|
|
||||||
scheduledPoll = null;
|
scheduledPoll = null;
|
||||||
pollingActive = true;
|
pollingActive = true;
|
||||||
Poll().ContinueWith(_ => pollComplete());
|
Poll().ContinueWith(_ => pollComplete());
|
||||||
@ -96,13 +100,13 @@ namespace osu.Game.Online
|
|||||||
|
|
||||||
if (!lastTimePolled.HasValue)
|
if (!lastTimePolled.HasValue)
|
||||||
{
|
{
|
||||||
doPoll();
|
Scheduler.AddOnce(doPoll);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Time.Current - lastTimePolled.Value > TimeBetweenPolls.Value)
|
if (Time.Current - lastTimePolled.Value > TimeBetweenPolls.Value)
|
||||||
{
|
{
|
||||||
doPoll();
|
Scheduler.AddOnce(doPoll);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private GetRoomsRequest pollReq;
|
private GetRoomsRequest lastPollRequest;
|
||||||
|
|
||||||
protected override Task Poll()
|
protected override Task Poll()
|
||||||
{
|
{
|
||||||
@ -45,10 +45,11 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
|||||||
|
|
||||||
var tcs = new TaskCompletionSource<bool>();
|
var tcs = new TaskCompletionSource<bool>();
|
||||||
|
|
||||||
pollReq?.Cancel();
|
lastPollRequest?.Cancel();
|
||||||
pollReq = new GetRoomsRequest(Filter.Value.Status, Filter.Value.Category);
|
|
||||||
|
|
||||||
pollReq.Success += result =>
|
var req = new GetRoomsRequest(Filter.Value.Status, Filter.Value.Category);
|
||||||
|
|
||||||
|
req.Success += result =>
|
||||||
{
|
{
|
||||||
foreach (var existing in RoomManager.Rooms.ToArray())
|
foreach (var existing in RoomManager.Rooms.ToArray())
|
||||||
{
|
{
|
||||||
@ -66,10 +67,11 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
|||||||
tcs.SetResult(true);
|
tcs.SetResult(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
pollReq.Failure += _ => tcs.SetResult(false);
|
req.Failure += _ => tcs.SetResult(false);
|
||||||
|
|
||||||
API.Queue(pollReq);
|
API.Queue(req);
|
||||||
|
|
||||||
|
lastPollRequest = req;
|
||||||
return tcs.Task;
|
return tcs.Task;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
|||||||
this.room = room;
|
this.room = room;
|
||||||
}
|
}
|
||||||
|
|
||||||
private GetRoomRequest pollReq;
|
private GetRoomRequest lastPollRequest;
|
||||||
|
|
||||||
protected override Task Poll()
|
protected override Task Poll()
|
||||||
{
|
{
|
||||||
@ -30,19 +30,22 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
|||||||
|
|
||||||
var tcs = new TaskCompletionSource<bool>();
|
var tcs = new TaskCompletionSource<bool>();
|
||||||
|
|
||||||
pollReq?.Cancel();
|
lastPollRequest?.Cancel();
|
||||||
pollReq = new GetRoomRequest(room.RoomID.Value.Value);
|
|
||||||
|
|
||||||
pollReq.Success += result =>
|
var req = new GetRoomRequest(room.RoomID.Value.Value);
|
||||||
|
|
||||||
|
req.Success += result =>
|
||||||
{
|
{
|
||||||
result.RemoveExpiredPlaylistItems();
|
result.RemoveExpiredPlaylistItems();
|
||||||
RoomManager.AddOrUpdateRoom(result);
|
RoomManager.AddOrUpdateRoom(result);
|
||||||
tcs.SetResult(true);
|
tcs.SetResult(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
pollReq.Failure += _ => tcs.SetResult(false);
|
req.Failure += _ => tcs.SetResult(false);
|
||||||
|
|
||||||
API.Queue(pollReq);
|
API.Queue(req);
|
||||||
|
|
||||||
|
lastPollRequest = req;
|
||||||
|
|
||||||
return tcs.Task;
|
return tcs.Task;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user