From f68aa94dc3cdc45856d3888b259234c69c6a2567 Mon Sep 17 00:00:00 2001 From: rootdarkarchon Date: Sun, 29 Jan 2023 20:42:54 +0100 Subject: [PATCH] fixes for when removing a pair or client --- MareSynchronos/Managers/PairManager.cs | 10 +++++++++- .../WebAPI/ApIController.Functions.Files.cs | 14 +++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/MareSynchronos/Managers/PairManager.cs b/MareSynchronos/Managers/PairManager.cs index 7792d64..0830b27 100644 --- a/MareSynchronos/Managers/PairManager.cs +++ b/MareSynchronos/Managers/PairManager.cs @@ -87,7 +87,11 @@ public class PairManager : IDisposable if (!_allClientPairs[item.Key].HasAnyConnection()) { - _allClientPairs.TryRemove(item.Key, out _); + if (_allClientPairs.TryRemove(item.Key, out var pair)) + { + pair.CachedPlayer?.Dispose(); + pair.CachedPlayer = null; + } } } RecreateLazy(); @@ -197,6 +201,8 @@ public class PairManager : IDisposable if (!pair.HasAnyConnection()) { + pair.CachedPlayer?.Dispose(); + pair.CachedPlayer = null; _allClientPairs.TryRemove(dto.User, out _); } @@ -211,6 +217,8 @@ public class PairManager : IDisposable pair.UserPair = null; if (!pair.HasAnyConnection()) { + pair.CachedPlayer?.Dispose(); + pair.CachedPlayer = null; _allClientPairs.TryRemove(dto.User, out _); } else diff --git a/MareSynchronos/WebAPI/ApIController.Functions.Files.cs b/MareSynchronos/WebAPI/ApIController.Functions.Files.cs index 482eef0..69486a5 100644 --- a/MareSynchronos/WebAPI/ApIController.Functions.Files.cs +++ b/MareSynchronos/WebAPI/ApIController.Functions.Files.cs @@ -219,9 +219,17 @@ public partial class ApiController Logger.Debug("Sending " + requestMessage.Method + " to " + requestMessage.RequestUri); } - if (ct != null) - return await _httpClient.SendAsync(requestMessage, ct.Value).ConfigureAwait(false); - return await _httpClient.SendAsync(requestMessage).ConfigureAwait(false); + try + { + if (ct != null) + return await _httpClient.SendAsync(requestMessage, ct.Value).ConfigureAwait(false); + return await _httpClient.SendAsync(requestMessage).ConfigureAwait(false); + } + catch (Exception ex) + { + Logger.Error("Error during SendRequestInternal for " + requestMessage.RequestUri, ex); + throw; + } } private async Task SendRequestAsync(HttpMethod method, Uri uri, T content, CancellationToken ct) where T : class