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
This commit is contained in:
Archi
2023-05-23 14:21:29 +02:00
parent e782f14cbf
commit 53fc07638d

View File

@@ -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<uint, (EPaymentMethod PaymentMethod, DateTime TimeCreated)>.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