Fixed: Close all database connections on shutdown

pull/793/head
ta264 3 years ago committed by Qstick
parent 97f4a2e651
commit 8701e67b1e

@ -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();

@ -1,3 +1,4 @@
using System.Data.SQLite;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
@ -6,6 +7,7 @@ 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;
namespace NzbDrone.Host namespace NzbDrone.Host
@ -99,6 +101,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)

@ -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;
@ -99,6 +100,11 @@ namespace NzbDrone.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();
} }
public static IHostBuilder CreateConsoleHostBuilder(string[] args, StartupContext context) public static IHostBuilder CreateConsoleHostBuilder(string[] args, StartupContext context)

Loading…
Cancel
Save