1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 11:12:54 +08:00

Fix bundle send logic not correctly waiting for task completion (due to nested schedule)

This commit is contained in:
Dean Herbert 2022-02-24 02:19:12 +09:00
parent c94e7e2abe
commit 47b84295a6

View File

@ -221,8 +221,7 @@ namespace osu.Game.Online.Spectator
protected abstract Task BeginPlayingInternal(SpectatorState state);
protected abstract Task SendFramesInternal(FrameDataBundle data);
protected abstract Task SendFramesInternal(FrameDataBundle bundle);
protected abstract Task EndPlayingInternal(SpectatorState state);
protected abstract Task WatchUserInternal(int userId);
@ -281,19 +280,27 @@ namespace osu.Game.Online.Spectator
private void sendNextBundleIfRequired()
{
Debug.Assert(ThreadSafety.IsUpdateThread);
if (lastSend?.IsCompleted == false)
return;
if (!pendingFrameBundles.TryPeek(out var bundle))
return;
lastSend = SendFramesInternal(bundle);
lastSend.ContinueWith(t => Schedule(() =>
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
lastSend = tcs.Task;
SendFramesInternal(bundle).ContinueWith(t => Schedule(() =>
{
bool wasSuccessful = t.Exception == null;
// If the last bundle send wasn't successful, try again without dequeuing.
if (t.IsCompletedSuccessfully)
if (wasSuccessful)
pendingFrameBundles.Dequeue();
tcs.SetResult(wasSuccessful);
sendNextBundleIfRequired();
}));
}