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

Fix web requests not getting correctly handled on first connection

This commit is contained in:
Dean Herbert 2018-12-17 14:29:11 +09:00
parent 0b5f3c00bf
commit 00998d5443

View File

@ -141,7 +141,7 @@ namespace osu.Game.Online.API
State = APIState.Online;
};
if (!handleRequest(userReq))
if (!handleRequest(userReq, out _))
{
Thread.Sleep(500);
continue;
@ -170,11 +170,15 @@ namespace osu.Game.Online.API
lock (queue)
{
if (queue.Count == 0) break;
req = queue.Dequeue();
req = queue.Peek();
}
// TODO: handle failures better
handleRequest(req);
handleRequest(req, out var removeFromQueue);
if (removeFromQueue)
lock (queue)
queue.Dequeue();
}
Thread.Sleep(50);
@ -193,9 +197,11 @@ namespace osu.Game.Online.API
/// Handle a single API request.
/// </summary>
/// <param name="req">The request.</param>
/// <returns>true if we should remove this request from the queue.</returns>
private bool handleRequest(APIRequest req)
/// <returns>true if the request succeeded.</returns>
private bool handleRequest(APIRequest req, out bool removeFromQueue)
{
removeFromQueue = true;
try
{
Logger.Log($@"Performing request {req}", LoggingTarget.Network);
@ -216,12 +222,12 @@ namespace osu.Game.Online.API
}
catch (WebException we)
{
var removeFromQueue = handleWebException(we);
removeFromQueue = handleWebException(we);
if (removeFromQueue)
req.Fail(we);
return removeFromQueue;
return false;
}
catch (Exception e)
{
@ -229,7 +235,7 @@ namespace osu.Game.Online.API
log.Add(@"API level timeout exception was hit");
req.Fail(e);
return true;
return false;
}
}