From 4d0a6fc330db1ae9afbe2607e2c985c7187e04b0 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Fri, 22 Jan 2021 00:24:01 +0100 Subject: [PATCH] Plugins - Fixed a deadlock during plugin load --- .../Services/PluginManagementService.cs | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/Artemis.Core/Services/PluginManagementService.cs b/src/Artemis.Core/Services/PluginManagementService.cs index bf18f1dde..af53c79a5 100644 --- a/src/Artemis.Core/Services/PluginManagementService.cs +++ b/src/Artemis.Core/Services/PluginManagementService.cs @@ -196,25 +196,24 @@ namespace Artemis.Core.Services } } - lock (_plugins) + // ReSharper disable InconsistentlySynchronizedField - It's read-only, idc + _logger.Debug("Loaded {count} plugin(s)", _plugins.Count); + + bool mustElevate = !isElevated && _plugins.Any(p => p.Entity.IsEnabled && p.Info.RequiresAdmin); + if (mustElevate) { - _logger.Debug("Loaded {count} plugin(s)", _plugins.Count); - - bool mustElevate = !isElevated && _plugins.Any(p => p.Entity.IsEnabled && p.Info.RequiresAdmin); - if (mustElevate) - { - _logger.Information("Restarting because one or more plugins requires elevation"); - // No need for a delay this early on, nothing that needs graceful shutdown is happening yet - Utilities.Restart(true, TimeSpan.Zero); - return; - } - - foreach (Plugin plugin in _plugins.Where(p => p.Entity.IsEnabled)) - EnablePlugin(plugin, false, ignorePluginLock); - - _logger.Debug("Enabled {count} plugin(s)", _plugins.Where(p => p.IsEnabled).Sum(p => p.Features.Count(f => f.IsEnabled))); + _logger.Information("Restarting because one or more plugins requires elevation"); + // No need for a delay this early on, nothing that needs graceful shutdown is happening yet + Utilities.Restart(true, TimeSpan.Zero); + return; } + foreach (Plugin plugin in _plugins.Where(p => p.Entity.IsEnabled)) + EnablePlugin(plugin, false, ignorePluginLock); + + _logger.Debug("Enabled {count} plugin(s)", _plugins.Where(p => p.IsEnabled).Sum(p => p.Features.Count(f => f.IsEnabled))); + // ReSharper restore InconsistentlySynchronizedField + LoadingPlugins = false; }