diff --git a/src/Examine/LuceneEngine/Providers/ErrorLoggingConcurrentMergeScheduler.cs b/src/Examine/LuceneEngine/Providers/ErrorLoggingConcurrentMergeScheduler.cs new file mode 100644 index 000000000..99738bf1a --- /dev/null +++ b/src/Examine/LuceneEngine/Providers/ErrorLoggingConcurrentMergeScheduler.cs @@ -0,0 +1,39 @@ +using System; +using System.Security; +using Lucene.Net.Index; + + +namespace Examine.LuceneEngine.Providers +{ + /// + /// Used to prevent the appdomain from crashing when lucene runs into a concurrent merge scheduler failure + /// + [SecurityCritical] + internal class ErrorLoggingConcurrentMergeScheduler : ConcurrentMergeScheduler + { + private readonly Action _logger; + + [SecurityCritical] + public ErrorLoggingConcurrentMergeScheduler(string indexName, Action logger) + { + IndexName = indexName; + _logger = logger; + } + + public string IndexName { get; } + + [SecurityCritical] + protected override void HandleMergeException(System.Exception exc) + { + try + { + base.HandleMergeException(exc); + } + catch (Exception e) + { + _logger($"Concurrent merge failed for index: {IndexName} if this error is persistent then index rebuilding is necessary", e); + } + } + } +} +