mirror of
https://github.com/lidarr/Lidarr
synced 2025-02-25 15:22:42 +00:00
Fixed: Close all database connections on shutdown to remove shm/wal files
(cherry picked from commit eb431f09fdede191bfe6bc6c2da9c8cb12d804a1)
This commit is contained in:
parent
4ba118d351
commit
ded8602976
3 changed files with 13 additions and 4 deletions
|
@ -16,12 +16,11 @@ public class DatabaseTarget : TargetWithLayout, IHandle<ApplicationShutdownReque
|
|||
private const string INSERT_COMMAND = "INSERT INTO [Logs]([Message],[Time],[Logger],[Exception],[ExceptionType],[Level]) " +
|
||||
"VALUES(@Message,@Time,@Logger,@Exception,@ExceptionType,@Level)";
|
||||
|
||||
private readonly SQLiteConnection _connection;
|
||||
private readonly IConnectionStringFactory _connectionStringFactory;
|
||||
|
||||
public DatabaseTarget(IConnectionStringFactory connectionStringFactory)
|
||||
{
|
||||
_connection = new SQLiteConnection(connectionStringFactory.LogDbConnectionString);
|
||||
_connection.Open();
|
||||
_connectionStringFactory = connectionStringFactory;
|
||||
}
|
||||
|
||||
public void Register()
|
||||
|
@ -56,6 +55,7 @@ protected override void Write(LogEventInfo logEvent)
|
|||
{
|
||||
try
|
||||
{
|
||||
using var connection = new SQLiteConnection(_connectionStringFactory.LogDbConnectionString).OpenAndReturn();
|
||||
var log = new Log();
|
||||
log.Time = logEvent.TimeStamp;
|
||||
log.Message = CleanseLogMessage.Cleanse(logEvent.FormattedMessage);
|
||||
|
@ -84,7 +84,7 @@ protected override void Write(LogEventInfo logEvent)
|
|||
|
||||
log.Level = logEvent.Level.Name;
|
||||
|
||||
var sqlCommand = new SQLiteCommand(INSERT_COMMAND, _connection);
|
||||
var sqlCommand = new SQLiteCommand(INSERT_COMMAND, connection);
|
||||
|
||||
sqlCommand.Parameters.Add(new SQLiteParameter("Message", DbType.String) { Value = log.Message });
|
||||
sqlCommand.Parameters.Add(new SQLiteParameter("Time", DbType.DateTime) { Value = log.Time.ToUniversalTime() });
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using System.Data.SQLite;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
@ -6,6 +7,7 @@
|
|||
using NzbDrone.Common.Processes;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
using NzbDrone.Core.Messaging;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
||||
namespace NzbDrone.Host
|
||||
|
@ -99,6 +101,7 @@ private string GetRestartArgs()
|
|||
return args;
|
||||
}
|
||||
|
||||
[EventHandleOrder(EventHandleOrder.Last)]
|
||||
public void Handle(ApplicationShutdownRequested message)
|
||||
{
|
||||
if (!_runtimeInfo.IsWindowsService)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SQLite;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
|
@ -102,6 +103,11 @@ public static void Start(string[] args, Action<IHostBuilder> trayCallback = null
|
|||
Logger.Info(ex.Message);
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue