fix crash on appdomain during reconnect

This commit is contained in:
Stanley Dimant
2023-02-24 09:08:14 +01:00
parent 78f0df9eaf
commit 242b6650ef
3 changed files with 21 additions and 15 deletions

View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<Authors></Authors> <Authors></Authors>
<Company></Company> <Company></Company>
<Version>0.7.37</Version> <Version>0.7.38</Version>
<Description></Description> <Description></Description>
<Copyright></Copyright> <Copyright></Copyright>
<PackageProjectUrl>https://github.com/Penumbra-Sync/client</PackageProjectUrl> <PackageProjectUrl>https://github.com/Penumbra-Sync/client</PackageProjectUrl>

View File

@@ -261,9 +261,9 @@ public partial class ApiController
Mediator.Publish(new NotificationMessage("Warning from " + _serverManager.CurrentServer!.ServerName, message, NotificationType.Warning, 7500)); Mediator.Publish(new NotificationMessage("Warning from " + _serverManager.CurrentServer!.ServerName, message, NotificationType.Warning, 7500));
break; break;
case MessageSeverity.Information: case MessageSeverity.Information:
if (_doNotNotifiyOnNextInfo) if (_doNotNotifyOnNextInfo)
{ {
_doNotNotifiyOnNextInfo = false; _doNotNotifyOnNextInfo = false;
break; break;
} }
Mediator.Publish(new NotificationMessage("Info from " + _serverManager.CurrentServer!.ServerName, message, NotificationType.Info, 5000)); Mediator.Publish(new NotificationMessage("Info from " + _serverManager.CurrentServer!.ServerName, message, NotificationType.Info, 5000));

View File

@@ -20,7 +20,6 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
public const string MainServer = "Lunae Crescere Incipientis (Central Server EU)"; public const string MainServer = "Lunae Crescere Incipientis (Central Server EU)";
public const string MainServiceUri = "wss://maresynchronos.com"; public const string MainServiceUri = "wss://maresynchronos.com";
public readonly int[] SupportedServerVersions = { IMareHub.ApiVersion };
private readonly HubFactory _hubFactory; private readonly HubFactory _hubFactory;
private readonly MareConfigService _configService; private readonly MareConfigService _configService;
private readonly DalamudUtil _dalamudUtil; private readonly DalamudUtil _dalamudUtil;
@@ -32,16 +31,13 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
private CancellationTokenSource? _uploadCancellationTokenSource = new(); private CancellationTokenSource? _uploadCancellationTokenSource = new();
private CancellationTokenSource? _healthCheckTokenSource = new(); private CancellationTokenSource? _healthCheckTokenSource = new();
private bool _doNotNotifiyOnNextInfo = false; private bool _doNotNotifyOnNextInfo = false;
private ConnectionDto? _connectionDto; private ConnectionDto? _connectionDto;
public ServerInfo ServerInfo => _connectionDto?.ServerInfo ?? new ServerInfo(); public ServerInfo ServerInfo => _connectionDto?.ServerInfo ?? new ServerInfo();
public string AuthFailureMessage { get; private set; } = string.Empty; public string AuthFailureMessage { get; private set; } = string.Empty;
public SystemInfoDto SystemInfoDto { get; private set; } = new(); public SystemInfoDto SystemInfoDto { get; private set; } = new();
public bool IsModerator => (_connectionDto?.IsAdmin ?? false) || (_connectionDto?.IsModerator ?? false);
public bool IsAdmin => _connectionDto?.IsAdmin ?? false;
private HttpClient _httpClient; private HttpClient _httpClient;
@@ -326,7 +322,7 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
private void MareHubOnReconnecting(Exception? arg) private void MareHubOnReconnecting(Exception? arg)
{ {
_doNotNotifiyOnNextInfo = true; _doNotNotifyOnNextInfo = true;
_healthCheckTokenSource?.Cancel(); _healthCheckTokenSource?.Cancel();
ServerState = ServerState.Reconnecting; ServerState = ServerState.Reconnecting;
Mediator.Publish(new NotificationMessage("Connection lost", "Connection lost to " + _serverManager.CurrentServer!.ServerName, NotificationType.Warning, 5000)); Mediator.Publish(new NotificationMessage("Connection lost", "Connection lost to " + _serverManager.CurrentServer!.ServerName, NotificationType.Warning, 5000));
@@ -336,14 +332,23 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
private async void MareHubOnReconnected(string? arg) private async void MareHubOnReconnected(string? arg)
{ {
ServerState = ServerState.Connecting; ServerState = ServerState.Connecting;
await InitializeData().ConfigureAwait(false); try
_connectionDto = await GetConnectionDto().ConfigureAwait(false);
if (_connectionDto.ServerVersion != IMareHub.ApiVersion)
{ {
await StopConnection(ServerState.VersionMisMatch).ConfigureAwait(false); await InitializeData().ConfigureAwait(false);
return; _connectionDto = await GetConnectionDto().ConfigureAwait(false);
if (_connectionDto.ServerVersion != IMareHub.ApiVersion)
{
await StopConnection(ServerState.VersionMisMatch).ConfigureAwait(false);
return;
}
ServerState = ServerState.Connected;
} }
ServerState = ServerState.Connected; catch (Exception ex)
{
_logger.LogCritical(ex, "Failure to obtain data after reconnection");
await StopConnection(ServerState.Disconnected).ConfigureAwait(false);
}
} }
private async Task StopConnection(ServerState state) private async Task StopConnection(ServerState state)
@@ -361,6 +366,7 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
CurrentDownloads.Clear(); CurrentDownloads.Clear();
Mediator.Publish(new DisconnectedMessage()); Mediator.Publish(new DisconnectedMessage());
_mareHub = null; _mareHub = null;
_connectionDto = null;
} }
} }