mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 10:33:21 +08:00
Merge pull request #14046 from peppy/fix-rapid-reconnection
Fix `HubClientConnector` reconnecting with no delay on server-triggered error
This commit is contained in:
commit
2a94fc214f
@ -116,10 +116,7 @@ namespace osu.Game.Online
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.Log($"{clientName} connection error: {e}", LoggingTarget.Network);
|
await handleErrorAndDelay(e, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
// retry on any failure.
|
|
||||||
await Task.Delay(5000, cancellationToken).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -129,6 +126,15 @@ namespace osu.Game.Online
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles an exception and delays an async flow.
|
||||||
|
/// </summary>
|
||||||
|
private async Task handleErrorAndDelay(Exception exception, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
Logger.Log($"{clientName} connection error: {exception}", LoggingTarget.Network);
|
||||||
|
await Task.Delay(5000, cancellationToken).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
private HubConnection buildConnection(CancellationToken cancellationToken)
|
private HubConnection buildConnection(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var builder = new HubConnectionBuilder()
|
var builder = new HubConnectionBuilder()
|
||||||
@ -155,17 +161,18 @@ namespace osu.Game.Online
|
|||||||
return newConnection;
|
return newConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task onConnectionClosed(Exception? ex, CancellationToken cancellationToken)
|
private async Task onConnectionClosed(Exception? ex, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
isConnected.Value = false;
|
isConnected.Value = false;
|
||||||
|
|
||||||
Logger.Log(ex != null ? $"{clientName} lost connection: {ex}" : $"{clientName} disconnected", LoggingTarget.Network);
|
if (ex != null)
|
||||||
|
await handleErrorAndDelay(ex, cancellationToken).ConfigureAwait(false);
|
||||||
|
else
|
||||||
|
Logger.Log($"{clientName} disconnected", LoggingTarget.Network);
|
||||||
|
|
||||||
// make sure a disconnect wasn't triggered (and this is still the active connection).
|
// make sure a disconnect wasn't triggered (and this is still the active connection).
|
||||||
if (!cancellationToken.IsCancellationRequested)
|
if (!cancellationToken.IsCancellationRequested)
|
||||||
Task.Run(connect, default);
|
await Task.Run(connect, default).ConfigureAwait(false);
|
||||||
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task disconnect(bool takeLock)
|
private async Task disconnect(bool takeLock)
|
||||||
|
Loading…
Reference in New Issue
Block a user