From a5d22195f2bdd39bb030f2536b93af908070131e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 18 Nov 2022 13:45:46 +0900 Subject: [PATCH] Fix potential incorrect connection state resulting in null reference --- osu.Game/Online/PersistentEndpointClientConnector.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/osu.Game/Online/PersistentEndpointClientConnector.cs b/osu.Game/Online/PersistentEndpointClientConnector.cs index 2c4e127723..be76644745 100644 --- a/osu.Game/Online/PersistentEndpointClientConnector.cs +++ b/osu.Game/Online/PersistentEndpointClientConnector.cs @@ -145,7 +145,9 @@ private async Task handleErrorAndDelay(Exception exception, CancellationToken ca private async Task onConnectionClosed(Exception? ex, CancellationToken cancellationToken) { - isConnected.Value = false; + bool hasBeenCancelled = cancellationToken.IsCancellationRequested; + + await disconnect(true); if (ex != null) await handleErrorAndDelay(ex, cancellationToken).ConfigureAwait(false); @@ -153,7 +155,7 @@ private async Task onConnectionClosed(Exception? ex, CancellationToken cancellat Logger.Log($"{ClientName} disconnected", LoggingTarget.Network); // make sure a disconnect wasn't triggered (and this is still the active connection). - if (!cancellationToken.IsCancellationRequested) + if (!hasBeenCancelled) await Task.Run(connect, default).ConfigureAwait(false); } @@ -174,7 +176,9 @@ private async Task disconnect(bool takeLock) } finally { + isConnected.Value = false; CurrentConnection = null; + if (takeLock) connectionLock.Release(); }