From 53fc07638d690621ae7b64fb7134499f6fd03496 Mon Sep 17 00:00:00 2001 From: Archi Date: Tue, 23 May 2023 14:21:29 +0200 Subject: [PATCH] Slightly improve OnDisconnected() flow We've added possible delay initializing log on result, but this method is very time-sensitive and there is a possibility of race conditions if we don't reset other stuff, such as AWH, in timely manner ASAP. It makes sense to move waiting for log on result in a place that isn't so time-sensitive anymore. This can help with some nasty networking issues where AWH state would get e.g. disabled after already being initialized due to reconnection --- ArchiSteamFarm/Steam/Bot.cs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/ArchiSteamFarm/Steam/Bot.cs b/ArchiSteamFarm/Steam/Bot.cs index fe91b1b94..053b0b45f 100644 --- a/ArchiSteamFarm/Steam/Bot.cs +++ b/ArchiSteamFarm/Steam/Bot.cs @@ -2561,16 +2561,6 @@ public sealed class Bot : IAsyncDisposable, IDisposable { throw new InvalidOperationException(nameof(ASF.LoginRateLimitingSemaphore)); } - EResult lastLogOnResult = LastLogOnResult; - - if (lastLogOnResult == EResult.Invalid) { - // Allow for a very short delay to initialize LastLogOnResult - await Task.Delay(1000).ConfigureAwait(false); - - lastLogOnResult = LastLogOnResult; - } - - LastLogOnResult = EResult.Invalid; HeartBeatFailures = 0; StopConnectionFailureTimer(); StopPlayingWasBlockedTimer(); @@ -2587,6 +2577,17 @@ public sealed class Bot : IAsyncDisposable, IDisposable { FirstTradeSent = false; OwnedPackageIDs = ImmutableDictionary.Empty; + EResult lastLogOnResult = LastLogOnResult; + + if (lastLogOnResult == EResult.Invalid) { + // Allow for a very short delay to initialize LastLogOnResult + await Task.Delay(1000).ConfigureAwait(false); + + lastLogOnResult = LastLogOnResult; + } + + LastLogOnResult = EResult.Invalid; + await PluginsCore.OnBotDisconnected(this, lastLogOnResult).ConfigureAwait(false); // If we initiated disconnect, do not attempt to reconnect