Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Shazwazza committed Jul 14, 2020
1 parent 23aefe2 commit 400b8be
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/Examine/LuceneEngine/Providers/LuceneIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ protected virtual void AddDocument(Document doc, ValueSet valueSet, IndexWriter
if (docArgs.Cancel)
return;

// TODO: try/catch with OutOfMemoryException (see docs on UpdateDocument), though i've never seen this in real life
writer.UpdateDocument(new Term(ItemIdFieldName, valueSet.Id), doc);
}

Expand Down Expand Up @@ -760,11 +761,17 @@ private void SafelyProcessQueueItems(Action<IndexOperationEventArgs> onComplete)
// - need to explicitly define TaskContinuationOptions.DenyChildAttach + TaskScheduler.Default
if (onComplete != null)
{
_asyncTask.ContinueWith(
task => onComplete?.Invoke(new IndexOperationEventArgs(this, task.Result)),
_cancellationTokenSource.Token,
TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.DenyChildAttach,
TaskScheduler.Default);

// it is possible that the cancelation token can be canceled when this is called which will throw an exception
// and is only caught by the unhandled exception handler so we need to be pro-active here
if (!_cancellationTokenSource.IsCancellationRequested)
{
_asyncTask.ContinueWith(
task => onComplete?.Invoke(new IndexOperationEventArgs(this, task.Result)),
_cancellationTokenSource.Token,
TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.DenyChildAttach,
TaskScheduler.Default);
}
}
}
}
Expand All @@ -781,11 +788,16 @@ private void SafelyProcessQueueItems(Action<IndexOperationEventArgs> onComplete)
// - need to explicitly define TaskContinuationOptions.DenyChildAttach + TaskScheduler.Default
if (onComplete != null)
{
_asyncTask?.ContinueWith(
task => onComplete?.Invoke(new IndexOperationEventArgs(this, task.Result)),
_cancellationTokenSource.Token,
TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.DenyChildAttach,
TaskScheduler.Default);
// it is possible that the cancelation token can be canceled when this is called which will throw an exception
// and is only caught by the unhandled exception handler so we need to be pro-active here
if (!_cancellationTokenSource.IsCancellationRequested)
{
_asyncTask?.ContinueWith(
task => onComplete?.Invoke(new IndexOperationEventArgs(this, task.Result)),
_cancellationTokenSource.Token,
TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.DenyChildAttach,
TaskScheduler.Default);
}
}
}
}
Expand Down

0 comments on commit 400b8be

Please sign in to comment.