From fd89254d5a9898dbe3c8ad50077d0389ccbaaa86 Mon Sep 17 00:00:00 2001 From: Shaun Walker Date: Mon, 7 Mar 2022 12:19:00 -0500 Subject: [PATCH] fix #2041 - Server restart post module install fails with null exception --- .../Infrastructure/Jobs/HostedServiceBase.cs | 20 ++++++++++++++----- Oqtane.Server/Startup.cs | 1 + 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Oqtane.Server/Infrastructure/Jobs/HostedServiceBase.cs b/Oqtane.Server/Infrastructure/Jobs/HostedServiceBase.cs index 16140a09..f3f70ebe 100644 --- a/Oqtane.Server/Infrastructure/Jobs/HostedServiceBase.cs +++ b/Oqtane.Server/Infrastructure/Jobs/HostedServiceBase.cs @@ -266,17 +266,27 @@ namespace Oqtane.Infrastructure jobs.UpdateJob(job); } } + } + catch + { + // error updating the job + } - if (_executingTask == null) - { - return; - } + // stop called without start + if (_executingTask == null) + { + return; + } + try + { + // force cancellation of the executing method _cancellationTokenSource.Cancel(); } finally { - await Task.WhenAny(_executingTask, Task.Delay(Timeout.Infinite, cancellationToken)); + // wait until the task completes or the stop token triggers + await Task.WhenAny(_executingTask, Task.Delay(Timeout.Infinite, cancellationToken)).ConfigureAwait(false); } } diff --git a/Oqtane.Server/Startup.cs b/Oqtane.Server/Startup.cs index 34ca42d1..c3ec9217 100644 --- a/Oqtane.Server/Startup.cs +++ b/Oqtane.Server/Startup.cs @@ -58,6 +58,7 @@ namespace Oqtane services.AddLocalization(options => options.ResourcesPath = "Resources"); services.AddOptions>().Bind(Configuration.GetSection(SettingKeys.AvailableDatabasesSection)); + services.Configure(opts => opts.ShutdownTimeout = TimeSpan.FromSeconds(10)); // increase from default of 5 seconds services.AddServerSideBlazor() .AddCircuitOptions(options =>