Fixed: Close all database connections on shutdown

This commit is contained in:
Qstick 2022-11-20 11:47:28 -06:00
parent f9ef7e3578
commit 7d4865dea3
17 changed files with 31 additions and 26 deletions

View File

@ -14,8 +14,8 @@ using NzbDrone.Core.Datastore;
using NzbDrone.Core.Datastore.Extensions; using NzbDrone.Core.Datastore.Extensions;
using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
using NzbDrone.Host;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
using Radarr.Host;
namespace NzbDrone.Common.Test namespace NzbDrone.Common.Test
{ {

View File

@ -2,14 +2,12 @@ using System;
using System.IO; using System.IO;
using System.Net.Sockets; using System.Net.Sockets;
using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using NLog; using NLog;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Exceptions; using NzbDrone.Common.Exceptions;
using NzbDrone.Common.Instrumentation; using NzbDrone.Common.Instrumentation;
using Radarr.Host; using NzbDrone.Host;
using Radarr.Host.AccessControl; using NzbDrone.Host.AccessControl;
namespace NzbDrone.Console namespace NzbDrone.Console
{ {

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Data; using System.Data;
using System.Data.SQLite; using System.Data.SQLite;
using NLog; using NLog;
@ -128,7 +128,7 @@ namespace NzbDrone.Core.Instrumentation
private void WriteSqliteLog(Log log, string connectionString) private void WriteSqliteLog(Log log, string connectionString)
{ {
using (var connection = using (var connection =
SQLiteFactory.Instance.CreateConnection()) new SQLiteConnection(_connectionStringFactory.LogDbConnectionString).OpenAndReturn())
{ {
connection.ConnectionString = connectionString; connection.ConnectionString = connectionString;
connection.Open(); connection.Open();

View File

@ -20,9 +20,9 @@ using NzbDrone.Core.Indexers;
using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
using NzbDrone.Host;
using NzbDrone.SignalR; using NzbDrone.SignalR;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
using Radarr.Host;
using IServiceProvider = System.IServiceProvider; using IServiceProvider = System.IServiceProvider;
namespace NzbDrone.App.Test namespace NzbDrone.App.Test

View File

@ -3,8 +3,8 @@ using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common.Model; using NzbDrone.Common.Model;
using NzbDrone.Common.Processes; using NzbDrone.Common.Processes;
using NzbDrone.Host;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
using Radarr.Host;
namespace NzbDrone.App.Test namespace NzbDrone.App.Test
{ {

View File

@ -3,8 +3,8 @@ using NUnit.Framework;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Processes; using NzbDrone.Common.Processes;
using NzbDrone.Host;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
using Radarr.Host;
namespace NzbDrone.App.Test namespace NzbDrone.App.Test
{ {

View File

@ -5,7 +5,7 @@ using NLog;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
namespace Radarr.Host.AccessControl namespace NzbDrone.Host.AccessControl
{ {
public interface IFirewallAdapter public interface IFirewallAdapter
{ {

View File

@ -1,6 +1,6 @@
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
namespace Radarr.Host.AccessControl namespace NzbDrone.Host.AccessControl
{ {
public interface IRemoteAccessAdapter public interface IRemoteAccessAdapter
{ {

View File

@ -1,7 +1,7 @@
using System; using System;
using NzbDrone.Common.Exceptions; using NzbDrone.Common.Exceptions;
namespace Radarr.Host.AccessControl namespace NzbDrone.Host.AccessControl
{ {
public class RemoteAccessException : NzbDroneException public class RemoteAccessException : NzbDroneException
{ {

View File

@ -6,8 +6,8 @@ using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Processes; using NzbDrone.Common.Processes;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Messaging;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
using Radarr.Host;
namespace NzbDrone.Host namespace NzbDrone.Host
{ {
@ -100,6 +100,7 @@ namespace NzbDrone.Host
return args; return args;
} }
[EventHandleOrder(EventHandleOrder.Last)]
public void Handle(ApplicationShutdownRequested message) public void Handle(ApplicationShutdownRequested message)
{ {
if (!_runtimeInfo.IsWindowsService) if (!_runtimeInfo.IsWindowsService)

View File

@ -1,4 +1,4 @@
namespace Radarr.Host namespace NzbDrone.Host
{ {
public enum ApplicationModes public enum ApplicationModes
{ {

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data.SQLite;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
@ -14,6 +15,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Hosting.WindowsServices; using Microsoft.Extensions.Hosting.WindowsServices;
using NLog; using NLog;
using Npgsql;
using NzbDrone.Common.Composition.Extensions; using NzbDrone.Common.Composition.Extensions;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Exceptions; using NzbDrone.Common.Exceptions;
@ -22,10 +24,9 @@ using NzbDrone.Common.Instrumentation;
using NzbDrone.Common.Instrumentation.Extensions; using NzbDrone.Common.Instrumentation.Extensions;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Datastore.Extensions; using NzbDrone.Core.Datastore.Extensions;
using NzbDrone.Host;
using PostgresOptions = NzbDrone.Core.Datastore.PostgresOptions; using PostgresOptions = NzbDrone.Core.Datastore.PostgresOptions;
namespace Radarr.Host namespace NzbDrone.Host
{ {
public static class Bootstrap public static class Bootstrap
{ {
@ -111,6 +112,12 @@ namespace Radarr.Host
Logger.Info(e.Message); Logger.Info(e.Message);
LogManager.Configuration = null; 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) public static IHostBuilder CreateConsoleHostBuilder(string[] args, StartupContext context)

View File

@ -1,10 +1,10 @@
using System; using System;
using NLog; using NLog;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Processes; using NzbDrone.Common.Processes;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
namespace Radarr.Host namespace NzbDrone.Host
{ {
public interface IBrowserService public interface IBrowserService
{ {

View File

@ -1,10 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NLog; using NLog;
using NzbDrone.Common.Processes; using NzbDrone.Common.Processes;
namespace Radarr.Host namespace NzbDrone.Host
{ {
public interface ISingleInstancePolicy public interface ISingleInstancePolicy
{ {

View File

@ -19,11 +19,10 @@ using NzbDrone.Common.Serializer;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Instrumentation;
using NzbDrone.Host.AccessControl;
using NzbDrone.Http.Authentication; using NzbDrone.Http.Authentication;
using NzbDrone.SignalR; using NzbDrone.SignalR;
using Radarr.Api.V3.System; using Radarr.Api.V3.System;
using Radarr.Host;
using Radarr.Host.AccessControl;
using Radarr.Http; using Radarr.Http;
using Radarr.Http.Authentication; using Radarr.Http.Authentication;
using Radarr.Http.ErrorManagement; using Radarr.Http.ErrorManagement;

View File

@ -1,6 +1,6 @@
using System; using System;
namespace Radarr.Host namespace NzbDrone.Host
{ {
public class TerminateApplicationException : ApplicationException public class TerminateApplicationException : ApplicationException
{ {

View File

@ -2,10 +2,10 @@ using NLog;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Processes; using NzbDrone.Common.Processes;
using Radarr.Host.AccessControl; using NzbDrone.Host.AccessControl;
using IServiceProvider = NzbDrone.Common.IServiceProvider; using IServiceProvider = NzbDrone.Common.IServiceProvider;
namespace Radarr.Host namespace NzbDrone.Host
{ {
public interface IUtilityModeRouter public interface IUtilityModeRouter
{ {