From 66c2b4097efd874ef42cf8f78556f1b456e6eb7b Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Fri, 6 Dec 2024 05:13:58 +0300 Subject: [PATCH 1/2] Use Lock type --- src/OrchardCore.Build/OrchardCore.Commons.props | 2 +- .../Services/LuceneIndexManager.cs | 3 ++- .../Modules/ModularApplicationContext.cs | 2 +- .../Modules/ModuleProjectStaticFileProvider.cs | 2 +- .../LiquidViewsFeatureProvider.cs | 2 +- .../ModuleProjectLiquidFileProvider.cs | 2 +- .../Descriptors/DefaultShapeTableManager.cs | 2 +- .../ComponentViewLocationExpanderProvider.cs | 2 +- .../SharedViewLocationExpanderProvider.cs | 2 +- .../ModuleProjectRazorFileProvider.cs | 2 +- .../OrchardCore.Mvc.Core/SharedViewCompilerProvider.cs | 2 +- .../OrchardCore.Mvc.Core/ShellFeatureApplicationPart.cs | 2 +- .../OrchardCore/Extensions/ExtensionManager.cs | 2 +- .../Overrides/HttpClient/ActiveHandlerTrackingEntry.cs | 4 ++-- .../Overrides/HttpClient/TenantHttpClientFactory.cs | 8 ++++---- 15 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/OrchardCore.Build/OrchardCore.Commons.props b/src/OrchardCore.Build/OrchardCore.Commons.props index 420863b3665..e58f93ca332 100644 --- a/src/OrchardCore.Build/OrchardCore.Commons.props +++ b/src/OrchardCore.Build/OrchardCore.Commons.props @@ -1,7 +1,7 @@ - 12.0 + 13.0 3.0.0 preview $(VersionSuffix)-$(BuildNumber) diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexManager.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexManager.cs index dbef75a0b59..5d5c9821584 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexManager.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexManager.cs @@ -14,6 +14,7 @@ using OrchardCore.Search.Lucene.Model; using OrchardCore.Search.Lucene.Services; using Spatial4n.Context; +using Lock = System.Threading.Lock; using Directory = System.IO.Directory; using LDirectory = Lucene.Net.Store.Directory; using LuceneLock = Lucene.Net.Store.Lock; @@ -37,7 +38,7 @@ public class LuceneIndexManager : IDisposable private readonly LuceneIndexSettingsService _luceneIndexSettingsService; private readonly SpatialContext _ctx; private readonly GeohashPrefixTree _grid; - private static readonly object _synLock = new(); + private static readonly Lock _synLock = new(); public LuceneIndexManager( IClock clock, diff --git a/src/OrchardCore/OrchardCore.Abstractions/Modules/ModularApplicationContext.cs b/src/OrchardCore/OrchardCore.Abstractions/Modules/ModularApplicationContext.cs index eca2895c334..2492d50ddd5 100644 --- a/src/OrchardCore/OrchardCore.Abstractions/Modules/ModularApplicationContext.cs +++ b/src/OrchardCore/OrchardCore.Abstractions/Modules/ModularApplicationContext.cs @@ -8,7 +8,7 @@ public class ModularApplicationContext : IApplicationContext private readonly IHostEnvironment _environment; private readonly IEnumerable _moduleNamesProviders; private Application _application; - private static readonly object _initLock = new(); + private static readonly Lock _initLock = new(); public ModularApplicationContext(IHostEnvironment environment, IEnumerable moduleNamesProviders) { diff --git a/src/OrchardCore/OrchardCore.Abstractions/Modules/ModuleProjectStaticFileProvider.cs b/src/OrchardCore/OrchardCore.Abstractions/Modules/ModuleProjectStaticFileProvider.cs index f7c8d591f3d..bca91e79fc1 100644 --- a/src/OrchardCore/OrchardCore.Abstractions/Modules/ModuleProjectStaticFileProvider.cs +++ b/src/OrchardCore/OrchardCore.Abstractions/Modules/ModuleProjectStaticFileProvider.cs @@ -11,7 +11,7 @@ namespace OrchardCore.Modules; public class ModuleProjectStaticFileProvider : IModuleStaticFileProvider { private static Dictionary _roots; - private static readonly object _synLock = new(); + private static readonly Lock _synLock = new(); public ModuleProjectStaticFileProvider(IApplicationContext applicationContext) { diff --git a/src/OrchardCore/OrchardCore.DisplayManagement.Liquid/LiquidViewsFeatureProvider.cs b/src/OrchardCore/OrchardCore.DisplayManagement.Liquid/LiquidViewsFeatureProvider.cs index 9978664b55b..02a06403862 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement.Liquid/LiquidViewsFeatureProvider.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement.Liquid/LiquidViewsFeatureProvider.cs @@ -16,7 +16,7 @@ public class LiquidViewsFeatureProvider : IApplicationFeatureProvider _sharedPaths; - private static readonly object _synLock = new(); + private static readonly Lock _synLock = new(); public LiquidViewsFeatureProvider(IOptions templateOptions) { diff --git a/src/OrchardCore/OrchardCore.DisplayManagement.Liquid/ModuleProjectLiquidFileProvider.cs b/src/OrchardCore/OrchardCore.DisplayManagement.Liquid/ModuleProjectLiquidFileProvider.cs index 441b2f2947c..a747118f6dc 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement.Liquid/ModuleProjectLiquidFileProvider.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement.Liquid/ModuleProjectLiquidFileProvider.cs @@ -12,7 +12,7 @@ namespace OrchardCore.DisplayManagement.Liquid; public class ModuleProjectLiquidFileProvider : IFileProvider { private static Dictionary _paths; - private static readonly object _synLock = new(); + private static readonly Lock _synLock = new(); public ModuleProjectLiquidFileProvider(IApplicationContext applicationContext) { diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Descriptors/DefaultShapeTableManager.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Descriptors/DefaultShapeTableManager.cs index ad3964c03dd..56f0eb2d4bb 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Descriptors/DefaultShapeTableManager.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Descriptors/DefaultShapeTableManager.cs @@ -22,7 +22,7 @@ public class DefaultShapeTableManager : IShapeTableManager // create a unique list of these per tenant. private static readonly ConcurrentDictionary _shapeDescriptors = new(); - private static readonly object _syncLock = new(); + private static readonly Lock _syncLock = new(); // Singleton cache to hold a tenant's theme ShapeTable. private readonly IDictionary _shapeTableCache; diff --git a/src/OrchardCore/OrchardCore.Mvc.Core/LocationExpander/ComponentViewLocationExpanderProvider.cs b/src/OrchardCore/OrchardCore.Mvc.Core/LocationExpander/ComponentViewLocationExpanderProvider.cs index 1223f1c33f1..13a4b252f33 100644 --- a/src/OrchardCore/OrchardCore.Mvc.Core/LocationExpander/ComponentViewLocationExpanderProvider.cs +++ b/src/OrchardCore/OrchardCore.Mvc.Core/LocationExpander/ComponentViewLocationExpanderProvider.cs @@ -14,7 +14,7 @@ public class ComponentViewLocationExpanderProvider : IViewLocationExpanderProvid private const string CacheKey = "ModuleComponentViewLocations"; private static List _modulesWithComponentViews; private static List _modulesWithPagesComponentViews; - private static readonly object _synLock = new(); + private static readonly Lock _synLock = new(); private static bool _initialized; private readonly IExtensionManager _extensionManager; diff --git a/src/OrchardCore/OrchardCore.Mvc.Core/LocationExpander/SharedViewLocationExpanderProvider.cs b/src/OrchardCore/OrchardCore.Mvc.Core/LocationExpander/SharedViewLocationExpanderProvider.cs index 4e0d2ab19cd..4a9010650ef 100644 --- a/src/OrchardCore/OrchardCore.Mvc.Core/LocationExpander/SharedViewLocationExpanderProvider.cs +++ b/src/OrchardCore/OrchardCore.Mvc.Core/LocationExpander/SharedViewLocationExpanderProvider.cs @@ -16,7 +16,7 @@ public class SharedViewLocationExpanderProvider : IViewLocationExpanderProvider private const string PageCacheKey = "ModulePageSharedViewLocations"; private static List _modulesWithPageSharedViews; private static List _modulesWithSharedViews; - private static readonly object _synLock = new(); + private static readonly Lock _synLock = new(); private readonly IExtensionManager _extensionManager; private readonly ShellDescriptor _shellDescriptor; diff --git a/src/OrchardCore/OrchardCore.Mvc.Core/ModuleProjectRazorFileProvider.cs b/src/OrchardCore/OrchardCore.Mvc.Core/ModuleProjectRazorFileProvider.cs index 792767d1979..06efb8f9b38 100644 --- a/src/OrchardCore/OrchardCore.Mvc.Core/ModuleProjectRazorFileProvider.cs +++ b/src/OrchardCore/OrchardCore.Mvc.Core/ModuleProjectRazorFileProvider.cs @@ -14,7 +14,7 @@ public class ModuleProjectRazorFileProvider : IFileProvider { private static List _pageFileProviders; private static Dictionary _roots; - private static readonly object _synLock = new(); + private static readonly Lock _synLock = new(); public ModuleProjectRazorFileProvider(IApplicationContext applicationContext) { diff --git a/src/OrchardCore/OrchardCore.Mvc.Core/SharedViewCompilerProvider.cs b/src/OrchardCore/OrchardCore.Mvc.Core/SharedViewCompilerProvider.cs index 3dbaf58775d..f57dd51499f 100644 --- a/src/OrchardCore/OrchardCore.Mvc.Core/SharedViewCompilerProvider.cs +++ b/src/OrchardCore/OrchardCore.Mvc.Core/SharedViewCompilerProvider.cs @@ -8,7 +8,7 @@ namespace OrchardCore.Mvc; /// public class SharedViewCompilerProvider : IViewCompilerProvider { - private readonly object _synLock = new(); + private readonly Lock _synLock = new(); private static IViewCompiler _compiler; private readonly IServiceProvider _services; diff --git a/src/OrchardCore/OrchardCore.Mvc.Core/ShellFeatureApplicationPart.cs b/src/OrchardCore/OrchardCore.Mvc.Core/ShellFeatureApplicationPart.cs index a6d1f789466..ea025676618 100644 --- a/src/OrchardCore/OrchardCore.Mvc.Core/ShellFeatureApplicationPart.cs +++ b/src/OrchardCore/OrchardCore.Mvc.Core/ShellFeatureApplicationPart.cs @@ -17,7 +17,7 @@ public class ShellFeatureApplicationPart : ICompilationReferencesProvider { private static IEnumerable _referencePaths; - private static readonly object _synLock = new(); + private static readonly Lock _synLock = new(); private ShellBlueprint _shellBlueprint; private IEnumerable _tagHelpers; diff --git a/src/OrchardCore/OrchardCore/Extensions/ExtensionManager.cs b/src/OrchardCore/OrchardCore/Extensions/ExtensionManager.cs index e9d35fc3c37..387d275d45a 100644 --- a/src/OrchardCore/OrchardCore/Extensions/ExtensionManager.cs +++ b/src/OrchardCore/OrchardCore/Extensions/ExtensionManager.cs @@ -28,7 +28,7 @@ public sealed class ExtensionManager : IExtensionManager private readonly ConcurrentDictionary>> _dependentFeatures = new(); private bool _isInitialized; - private readonly object _synLock = new(); + private readonly Lock _synLock = new(); public ExtensionManager( IServiceProvider serviceProvider, diff --git a/src/OrchardCore/OrchardCore/Modules/Overrides/HttpClient/ActiveHandlerTrackingEntry.cs b/src/OrchardCore/OrchardCore/Modules/Overrides/HttpClient/ActiveHandlerTrackingEntry.cs index 42f0a061fb5..93adf42aae0 100644 --- a/src/OrchardCore/OrchardCore/Modules/Overrides/HttpClient/ActiveHandlerTrackingEntry.cs +++ b/src/OrchardCore/OrchardCore/Modules/Overrides/HttpClient/ActiveHandlerTrackingEntry.cs @@ -12,7 +12,7 @@ namespace Microsoft.Extensions.Http; internal sealed class ActiveHandlerTrackingEntry : IDisposable { private static readonly TimerCallback _timerCallback = (s) => ((ActiveHandlerTrackingEntry)s!).Timer_Tick(); - private readonly object _lock; + private readonly Lock _lock; private bool _timerInitialized; private Timer _timer; private TimerCallback _callback; @@ -31,7 +31,7 @@ public ActiveHandlerTrackingEntry( Scope = scope; Lifetime = lifetime; - _lock = new object(); + _lock = new(); } public LifetimeTrackingHttpMessageHandler Handler { get; private set; } diff --git a/src/OrchardCore/OrchardCore/Modules/Overrides/HttpClient/TenantHttpClientFactory.cs b/src/OrchardCore/OrchardCore/Modules/Overrides/HttpClient/TenantHttpClientFactory.cs index 656be81c3fe..18ebc40dea9 100644 --- a/src/OrchardCore/OrchardCore/Modules/Overrides/HttpClient/TenantHttpClientFactory.cs +++ b/src/OrchardCore/OrchardCore/Modules/Overrides/HttpClient/TenantHttpClientFactory.cs @@ -40,8 +40,8 @@ internal sealed class TenantHttpClientFactory : IHttpClientFactory, IHttpMessage // There's no need for the factory itself to be disposable. If you stop using it, eventually everything will // get reclaimed. private Timer? _cleanupTimer; - private readonly object _cleanupTimerLock; - private readonly object _cleanupActiveLock; + private readonly Lock _cleanupTimerLock; + private readonly Lock _cleanupActiveLock; // Collection of 'active' handlers. // @@ -94,8 +94,8 @@ public TenantHttpClientFactory( _expiredHandlers = new ConcurrentQueue(); _expiryCallback = ExpiryTimer_Tick; - _cleanupTimerLock = new object(); - _cleanupActiveLock = new object(); + _cleanupTimerLock = new Lock(); + _cleanupActiveLock = new Lock(); // We want to prevent a circular dependency between ILoggerFactory and IHttpClientFactory, in case // any of ILoggerProvider instances use IHttpClientFactory to send logs to an external server. From eceddc0034878f7ed1fa9576868df3e39a1f4576 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Fri, 6 Dec 2024 05:36:06 +0300 Subject: [PATCH 2/2] Replace monitor --- .../Modules/Overrides/HttpClient/TenantHttpClientFactory.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OrchardCore/OrchardCore/Modules/Overrides/HttpClient/TenantHttpClientFactory.cs b/src/OrchardCore/OrchardCore/Modules/Overrides/HttpClient/TenantHttpClientFactory.cs index 18ebc40dea9..6383df1f99f 100644 --- a/src/OrchardCore/OrchardCore/Modules/Overrides/HttpClient/TenantHttpClientFactory.cs +++ b/src/OrchardCore/OrchardCore/Modules/Overrides/HttpClient/TenantHttpClientFactory.cs @@ -274,7 +274,7 @@ internal void CleanupTimer_Tick() // whether we need to start the timer. StopCleanupTimer(); - if (!Monitor.TryEnter(_cleanupActiveLock)) + if (!_cleanupActiveLock.TryEnter()) { // We don't want to run a concurrent cleanup cycle. This can happen if the cleanup cycle takes // a long time for some reason. Since we're running user code inside Dispose, it's definitely @@ -332,7 +332,7 @@ internal void CleanupTimer_Tick() } finally { - Monitor.Exit(_cleanupActiveLock); + _cleanupActiveLock.Exit(); } // We didn't totally empty the cleanup queue, try again later.