From c5fa818630c25ee7b3912de0d1bfeca9194bc7a3 Mon Sep 17 00:00:00 2001
From: Dean Herbert <pe@ppy.sh>
Date: Fri, 5 Feb 2021 14:08:11 +0900
Subject: [PATCH] Actually handle case of failing to achieve lock on
 SemaphoreSlim

---
 osu.Game/Online/Multiplayer/MultiplayerClient.cs | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/osu.Game/Online/Multiplayer/MultiplayerClient.cs b/osu.Game/Online/Multiplayer/MultiplayerClient.cs
index 9067c9a738..36cdf3bc8f 100644
--- a/osu.Game/Online/Multiplayer/MultiplayerClient.cs
+++ b/osu.Game/Online/Multiplayer/MultiplayerClient.cs
@@ -67,7 +67,8 @@ namespace osu.Game.Online.Multiplayer
         {
             cancelExistingConnect();
 
-            await connectionLock.WaitAsync(10000);
+            if (!await connectionLock.WaitAsync(10000))
+                throw new TimeoutException("Could not obtain a lock to connect. A previous attempt is likely stuck.");
 
             var builder = new HubConnectionBuilder()
                 .WithUrl(endpoint, options => { options.Headers.Add("Authorization", $"Bearer {api.AccessToken}"); });
@@ -199,7 +200,10 @@ namespace osu.Game.Online.Multiplayer
             cancelExistingConnect();
 
             if (takeLock)
-                await connectionLock.WaitAsync(10000);
+            {
+                if (!await connectionLock.WaitAsync(10000))
+                    throw new TimeoutException("Could not obtain a lock to disconnect. A previous attempt is likely stuck.");
+            }
 
             try
             {