From 0f7ba42987105c79acafc3770465a4fe5e3f3ee9 Mon Sep 17 00:00:00 2001 From: Luke Brown Date: Mon, 6 Jun 2022 23:59:09 -0500 Subject: [PATCH] move the Dispose logic into DisposeAsyncCore --- .../ApplicationHost.cs | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 4f74136337..899f5e30a8 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1234,7 +1234,7 @@ namespace Emby.Server.Implementations public async ValueTask DisposeAsync() { await DisposeAsyncCore().ConfigureAwait(false); - Dispose(true); + Dispose(false); GC.SuppressFinalize(this); } @@ -1244,6 +1244,31 @@ namespace Emby.Server.Implementations /// A ValueTask. protected virtual async ValueTask DisposeAsyncCore() { + var type = GetType(); + + Logger.LogInformation("Disposing {Type}", type.Name); + + foreach (var (part, _) in _disposableParts) + { + var partType = part.GetType(); + if (partType == type) + { + continue; + } + + Logger.LogInformation("Disposing {Type}", partType.Name); + + try + { + part.Dispose(); + } + catch (Exception ex) + { + Logger.LogError(ex, "Error disposing {Type}", partType.Name); + } + } + + // used for closing websockets foreach (var session in _sessionManager.Sessions) { await session.DisposeAsync().ConfigureAwait(false);