The Free Software Media System - Server Backend & API
Pls fix race condition
Bond_009032d72a8a7a1
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.csindex 0a7c5c1fb0..d7ac8bc3bb 100644--- a/Emby.Server.Implementations/ApplicationHost.cs+++ b/Emby.Server.Implementations/ApplicationHost.cs@@ -126,7 +126,6 @@ namespace Emby.Server.Implementationsprivate IMediaEncoder _mediaEncoder;private ISessionManager _sessionManager;private string[] _urlPrefixes;- private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.GetOptions();/// <summary>/// Gets a value indicating whether this instance can self restart.@@ -484,8 +483,9 @@ namespace Emby.Server.Implementations/// Runs the startup tasks./// </summary>/// <returns><see cref="Task" />.</returns>- public async Task RunStartupTasksAsync()+ public async Task RunStartupTasksAsync(CancellationToken cancellationToken){+ cancellationToken.ThrowIfCancellationRequested();Logger.LogInformation("Running startup tasks");Resolve<ITaskManager>().AddTasks(GetExports<IScheduledTask>(false));@@ -501,13 +501,15 @@ namespace Emby.Server.Implementationsvar stopWatch = new Stopwatch();stopWatch.Start();- await Task.WhenAll(StartEntryPoints(entryPoints, true)).ConfigureAwait(false);+ cancellationToken.ThrowIfCancellationRequested();+ await Task.WhenAny(Task.WhenAll(StartEntryPoints(entryPoints, true)), Task.Delay(-1, cancellationToken)).ConfigureAwait(false);Logger.LogInformation("Executed all pre-startup entry points in {Elapsed:g}", stopWatch.Elapsed);Logger.LogInformation("Core startup complete");CoreStartupHasCompleted = true;stopWatch.Restart();- await Task.WhenAll(StartEntryPoints(entryPoints, false)).ConfigureAwait(false);+ cancellationToken.ThrowIfCancellationRequested();+ await Task.WhenAny(Task.WhenAll(StartEntryPoints(entryPoints, false)), Task.Delay(-1, cancellationToken)).ConfigureAwait(false);Logger.LogInformation("Executed all post-startup entry points in {Elapsed:g}", stopWatch.Elapsed);stopWatch.Stop();}diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.csindex f05cdfe9bd..81199c7752 100644--- a/Jellyfin.Server/Program.cs+++ b/Jellyfin.Server/Program.cs@@ -202,7 +202,7 @@ namespace Jellyfin.Serverthrow;}- await appHost.RunStartupTasksAsync().ConfigureAwait(false);+ await appHost.RunStartupTasksAsync(_tokenSource.Token).ConfigureAwait(false);stopWatch.Stop();diff --git a/tests/Jellyfin.Api.Tests/JellyfinApplicationFactory.cs b/tests/Jellyfin.Api.Tests/JellyfinApplicationFactory.csindex dbbd5ac28c..ab7e0b6e7d 100644--- a/tests/Jellyfin.Api.Tests/JellyfinApplicationFactory.cs+++ b/tests/Jellyfin.Api.Tests/JellyfinApplicationFactory.cs@@ -1,6 +1,7 @@using System;using System.Collections.Concurrent;using System.IO;+using System.Threading;using Emby.Server.Implementations;using Emby.Server.Implementations.IO;using Jellyfin.Server;@@ -21,7 +22,7 @@ namespace Jellyfin.Api.Testspublic class JellyfinApplicationFactory : WebApplicationFactory<Startup>{private static readonly string _testPathRoot = Path.Combine(Path.GetTempPath(), "jellyfin-test-data");- private static readonly ConcurrentBag<IDisposable> _disposableComponents = new ConcurrentBag<IDisposable>();+ private readonly ConcurrentBag<IDisposable> _disposableComponents = new ConcurrentBag<IDisposable>();/// <summary>/// Initializes a new instance of the <see cref="JellyfinApplicationFactory"/> class.@@ -96,7 +97,7 @@ namespace Jellyfin.Api.Testsvar appHost = (TestAppHost)testServer.Services.GetRequiredService<IApplicationHost>();appHost.ServiceProvider = testServer.Services;appHost.InitializeServices().GetAwaiter().GetResult();- appHost.RunStartupTasksAsync().GetAwaiter().GetResult();+ appHost.RunStartupTasksAsync(CancellationToken.None).GetAwaiter().GetResult();return testServer;}