From 808c97fcb45edf2ba57273aa4db590cc58299875 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 24 Oct 2017 17:13:59 +0900 Subject: [PATCH] Fix multiple requests potentially being triggered during connect sequence As the Success callbacks happen in a scheduled context, if the Update thread is in a stalled state, this loop can generate many unnecessary API requests. --- osu.Game/Online/API/APIAccess.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/osu.Game/Online/API/APIAccess.cs b/osu.Game/Online/API/APIAccess.cs index bb72efb750..4e26b1b850 100644 --- a/osu.Game/Online/API/APIAccess.cs +++ b/osu.Game/Online/API/APIAccess.cs @@ -121,18 +121,28 @@ namespace osu.Game.Online.API continue; } - var userReq = new GetUserRequest(); userReq.Success += u => { LocalUser.Value = u; + failureCount = 0; + //we're connected! State = APIState.Online; - failureCount = 0; }; if (!handleRequest(userReq)) + { + Thread.Sleep(500); continue; + } + + // The Success callback event is fired on the main thread, so we should wait for that to run before proceeding. + // Without this, we will end up circulating this Connecting loop multiple times and queueing up many web requests + // before actually going online. + while (State != APIState.Online) + Thread.Sleep(500); + break; }