diff --git a/src/NzbDrone.Common.Test/ServiceFactoryFixture.cs b/src/NzbDrone.Common.Test/ServiceFactoryFixture.cs index 06e75831b..9c348316f 100644 --- a/src/NzbDrone.Common.Test/ServiceFactoryFixture.cs +++ b/src/NzbDrone.Common.Test/ServiceFactoryFixture.cs @@ -14,8 +14,8 @@ using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore.Extensions; using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Messaging.Events; +using NzbDrone.Host; using NzbDrone.Test.Common; -using Radarr.Host; namespace NzbDrone.Common.Test { diff --git a/src/NzbDrone.Console/ConsoleApp.cs b/src/NzbDrone.Console/ConsoleApp.cs index d52f40726..75fe1fb60 100644 --- a/src/NzbDrone.Console/ConsoleApp.cs +++ b/src/NzbDrone.Console/ConsoleApp.cs @@ -2,14 +2,12 @@ using System; using System.IO; using System.Net.Sockets; using Microsoft.AspNetCore.Connections; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Hosting; using NLog; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Exceptions; using NzbDrone.Common.Instrumentation; -using Radarr.Host; -using Radarr.Host.AccessControl; +using NzbDrone.Host; +using NzbDrone.Host.AccessControl; namespace NzbDrone.Console { diff --git a/src/NzbDrone.Core/Instrumentation/DatabaseTarget.cs b/src/NzbDrone.Core/Instrumentation/DatabaseTarget.cs index f8348c35e..04e08cf81 100644 --- a/src/NzbDrone.Core/Instrumentation/DatabaseTarget.cs +++ b/src/NzbDrone.Core/Instrumentation/DatabaseTarget.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Data; using System.Data.SQLite; using NLog; @@ -128,7 +128,7 @@ namespace NzbDrone.Core.Instrumentation private void WriteSqliteLog(Log log, string connectionString) { using (var connection = - SQLiteFactory.Instance.CreateConnection()) + new SQLiteConnection(_connectionStringFactory.LogDbConnectionString).OpenAndReturn()) { connection.ConnectionString = connectionString; connection.Open(); diff --git a/src/NzbDrone.Host.Test/ContainerFixture.cs b/src/NzbDrone.Host.Test/ContainerFixture.cs index e0f6a7a2e..b73665459 100644 --- a/src/NzbDrone.Host.Test/ContainerFixture.cs +++ b/src/NzbDrone.Host.Test/ContainerFixture.cs @@ -20,9 +20,9 @@ using NzbDrone.Core.Indexers; using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Events; +using NzbDrone.Host; using NzbDrone.SignalR; using NzbDrone.Test.Common; -using Radarr.Host; using IServiceProvider = System.IServiceProvider; namespace NzbDrone.App.Test diff --git a/src/NzbDrone.Host.Test/NzbDroneProcessServiceFixture.cs b/src/NzbDrone.Host.Test/NzbDroneProcessServiceFixture.cs index 992c81938..62cbf183e 100644 --- a/src/NzbDrone.Host.Test/NzbDroneProcessServiceFixture.cs +++ b/src/NzbDrone.Host.Test/NzbDroneProcessServiceFixture.cs @@ -3,8 +3,8 @@ using Moq; using NUnit.Framework; using NzbDrone.Common.Model; using NzbDrone.Common.Processes; +using NzbDrone.Host; using NzbDrone.Test.Common; -using Radarr.Host; namespace NzbDrone.App.Test { diff --git a/src/NzbDrone.Host.Test/RouterTest.cs b/src/NzbDrone.Host.Test/RouterTest.cs index 88ba0f98f..430b76867 100644 --- a/src/NzbDrone.Host.Test/RouterTest.cs +++ b/src/NzbDrone.Host.Test/RouterTest.cs @@ -3,8 +3,8 @@ using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Processes; +using NzbDrone.Host; using NzbDrone.Test.Common; -using Radarr.Host; namespace NzbDrone.App.Test { diff --git a/src/NzbDrone.Host/AccessControl/FirewallAdapter.cs b/src/NzbDrone.Host/AccessControl/FirewallAdapter.cs index 232babb72..d8d45cf97 100644 --- a/src/NzbDrone.Host/AccessControl/FirewallAdapter.cs +++ b/src/NzbDrone.Host/AccessControl/FirewallAdapter.cs @@ -5,7 +5,7 @@ using NLog; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Core.Configuration; -namespace Radarr.Host.AccessControl +namespace NzbDrone.Host.AccessControl { public interface IFirewallAdapter { diff --git a/src/NzbDrone.Host/AccessControl/RemoteAccessAdapter.cs b/src/NzbDrone.Host/AccessControl/RemoteAccessAdapter.cs index d46dc9807..21fe9bede 100644 --- a/src/NzbDrone.Host/AccessControl/RemoteAccessAdapter.cs +++ b/src/NzbDrone.Host/AccessControl/RemoteAccessAdapter.cs @@ -1,6 +1,6 @@ using NzbDrone.Common.EnvironmentInfo; -namespace Radarr.Host.AccessControl +namespace NzbDrone.Host.AccessControl { public interface IRemoteAccessAdapter { diff --git a/src/NzbDrone.Host/AccessControl/RemoteAccessException.cs b/src/NzbDrone.Host/AccessControl/RemoteAccessException.cs index aad1f9b77..71ea33052 100644 --- a/src/NzbDrone.Host/AccessControl/RemoteAccessException.cs +++ b/src/NzbDrone.Host/AccessControl/RemoteAccessException.cs @@ -1,7 +1,7 @@ using System; using NzbDrone.Common.Exceptions; -namespace Radarr.Host.AccessControl +namespace NzbDrone.Host.AccessControl { public class RemoteAccessException : NzbDroneException { diff --git a/src/NzbDrone.Host/AppLifetime.cs b/src/NzbDrone.Host/AppLifetime.cs index fc15cfc4a..be17ab714 100644 --- a/src/NzbDrone.Host/AppLifetime.cs +++ b/src/NzbDrone.Host/AppLifetime.cs @@ -6,8 +6,8 @@ using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Processes; using NzbDrone.Core.Configuration; using NzbDrone.Core.Lifecycle; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Messaging.Events; -using Radarr.Host; namespace NzbDrone.Host { @@ -100,6 +100,7 @@ namespace NzbDrone.Host return args; } + [EventHandleOrder(EventHandleOrder.Last)] public void Handle(ApplicationShutdownRequested message) { if (!_runtimeInfo.IsWindowsService) diff --git a/src/NzbDrone.Host/ApplicationModes.cs b/src/NzbDrone.Host/ApplicationModes.cs index 196aecde6..40920ac0e 100644 --- a/src/NzbDrone.Host/ApplicationModes.cs +++ b/src/NzbDrone.Host/ApplicationModes.cs @@ -1,4 +1,4 @@ -namespace Radarr.Host +namespace NzbDrone.Host { public enum ApplicationModes { diff --git a/src/NzbDrone.Host/Bootstrap.cs b/src/NzbDrone.Host/Bootstrap.cs index bc63e2737..9a0857e04 100644 --- a/src/NzbDrone.Host/Bootstrap.cs +++ b/src/NzbDrone.Host/Bootstrap.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Data.SQLite; using System.Diagnostics; using System.IO; using System.Reflection; @@ -14,6 +15,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting.WindowsServices; using NLog; +using Npgsql; using NzbDrone.Common.Composition.Extensions; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Exceptions; @@ -22,10 +24,9 @@ using NzbDrone.Common.Instrumentation; using NzbDrone.Common.Instrumentation.Extensions; using NzbDrone.Core.Configuration; using NzbDrone.Core.Datastore.Extensions; -using NzbDrone.Host; using PostgresOptions = NzbDrone.Core.Datastore.PostgresOptions; -namespace Radarr.Host +namespace NzbDrone.Host { public static class Bootstrap { @@ -111,6 +112,12 @@ namespace Radarr.Host Logger.Info(e.Message); LogManager.Configuration = null; } + + // Make sure there are no lingering database connections + GC.Collect(); + GC.WaitForPendingFinalizers(); + SQLiteConnection.ClearAllPools(); + NpgsqlConnection.ClearAllPools(); } public static IHostBuilder CreateConsoleHostBuilder(string[] args, StartupContext context) diff --git a/src/NzbDrone.Host/BrowserService.cs b/src/NzbDrone.Host/BrowserService.cs index 81ca0ed9a..f0636e563 100644 --- a/src/NzbDrone.Host/BrowserService.cs +++ b/src/NzbDrone.Host/BrowserService.cs @@ -1,10 +1,10 @@ -using System; +using System; using NLog; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Processes; using NzbDrone.Core.Configuration; -namespace Radarr.Host +namespace NzbDrone.Host { public interface IBrowserService { diff --git a/src/NzbDrone.Host/SingleInstancePolicy.cs b/src/NzbDrone.Host/SingleInstancePolicy.cs index dd2f74190..4380df733 100644 --- a/src/NzbDrone.Host/SingleInstancePolicy.cs +++ b/src/NzbDrone.Host/SingleInstancePolicy.cs @@ -1,10 +1,10 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using NLog; using NzbDrone.Common.Processes; -namespace Radarr.Host +namespace NzbDrone.Host { public interface ISingleInstancePolicy { diff --git a/src/NzbDrone.Host/Startup.cs b/src/NzbDrone.Host/Startup.cs index 4a7e848cf..2a2c10e52 100644 --- a/src/NzbDrone.Host/Startup.cs +++ b/src/NzbDrone.Host/Startup.cs @@ -19,11 +19,10 @@ using NzbDrone.Common.Serializer; using NzbDrone.Core.Configuration; using NzbDrone.Core.Datastore; using NzbDrone.Core.Instrumentation; +using NzbDrone.Host.AccessControl; using NzbDrone.Http.Authentication; using NzbDrone.SignalR; using Radarr.Api.V3.System; -using Radarr.Host; -using Radarr.Host.AccessControl; using Radarr.Http; using Radarr.Http.Authentication; using Radarr.Http.ErrorManagement; diff --git a/src/NzbDrone.Host/TerminateApplicationException.cs b/src/NzbDrone.Host/TerminateApplicationException.cs index fb86ad1c9..cbcc0ceb2 100644 --- a/src/NzbDrone.Host/TerminateApplicationException.cs +++ b/src/NzbDrone.Host/TerminateApplicationException.cs @@ -1,6 +1,6 @@ using System; -namespace Radarr.Host +namespace NzbDrone.Host { public class TerminateApplicationException : ApplicationException { diff --git a/src/NzbDrone.Host/UtilityModeRouter.cs b/src/NzbDrone.Host/UtilityModeRouter.cs index 2e276d097..61a8ce633 100644 --- a/src/NzbDrone.Host/UtilityModeRouter.cs +++ b/src/NzbDrone.Host/UtilityModeRouter.cs @@ -2,10 +2,10 @@ using NLog; using NzbDrone.Common; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Processes; -using Radarr.Host.AccessControl; +using NzbDrone.Host.AccessControl; using IServiceProvider = NzbDrone.Common.IServiceProvider; -namespace Radarr.Host +namespace NzbDrone.Host { public interface IUtilityModeRouter {