Move disconnect logic inside connection loop to ensure previous connection is disposed

This commit is contained in:
Dean Herbert 2021-01-26 18:59:42 +09:00
parent 0f09a7feb9
commit b573c96c07

View File

@ -71,14 +71,15 @@ namespace osu.Game.Online.Multiplayer
try try
{ {
await disconnect(false);
// this token will be valid for the scope of this connection. // this token will be valid for the scope of this connection.
// if cancelled, we can be sure that a disconnect or reconnect is handled elsewhere. // if cancelled, we can be sure that a disconnect or reconnect is handled elsewhere.
var cancellationToken = connectCancelSource.Token; var cancellationToken = connectCancelSource.Token;
while (api.State.Value == APIState.Online) while (api.State.Value == APIState.Online)
{ {
// ensure any previous connection was disposed.
await disconnect(false);
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
Logger.Log("Multiplayer client connecting...", LoggingTarget.Network); Logger.Log("Multiplayer client connecting...", LoggingTarget.Network);