From c16d71562e528e1ab03a717a624f2f4ccb355e16 Mon Sep 17 00:00:00 2001 From: Cody Robibero Date: Fri, 4 Feb 2022 12:36:17 -0700 Subject: [PATCH] Prevent additional errors on startup/shutdown (#6788) --- Jellyfin.Server/Program.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index f40526e223..05c59ebfb3 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -224,12 +224,16 @@ namespace Jellyfin.Server } finally { - _logger.LogInformation("Running query planner optimizations in the database... This might take a while"); - // Run before disposing the application - using var context = appHost.Resolve().CreateContext(); - if (context.Database.IsSqlite()) + // Don't throw additional exception if startup failed. + if (appHost.ServiceProvider != null) { - context.Database.ExecuteSqlRaw("PRAGMA optimize"); + _logger.LogInformation("Running query planner optimizations in the database... This might take a while"); + // Run before disposing the application + using var context = appHost.Resolve().CreateContext(); + if (context.Database.IsSqlite()) + { + context.Database.ExecuteSqlRaw("PRAGMA optimize"); + } } appHost.Dispose();