oops, forgot commit
This commit is contained in:
@@ -107,12 +107,26 @@ namespace Umbraco.Cms.Infrastructure.Examine
|
||||
{
|
||||
if (CanInitialize())
|
||||
{
|
||||
// Use SafeCallContext to prevent the current Execution Context (AsyncLocal) flow to child
|
||||
// Use ExecutionContext.SuppressFlow to prevent the current Execution Context (AsyncLocal) flow to child
|
||||
// tasks executed in the base class so we don't leak Scopes.
|
||||
// TODO: See notes at the top of this class
|
||||
using (ExecutionContext.SuppressFlow())
|
||||
{
|
||||
base.PerformDeleteFromIndex(itemIds, onComplete);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void PerformIndexItems(IEnumerable<ValueSet> values, Action<IndexOperationEventArgs> onComplete)
|
||||
{
|
||||
if (CanInitialize())
|
||||
{
|
||||
// Use ExecutionContext.SuppressFlow to prevent the current Execution Context (AsyncLocal) flow to child
|
||||
// tasks executed in the base class so we don't leak Scopes.
|
||||
// TODO: See notes at the top of this class
|
||||
using (ExecutionContext.SuppressFlow())
|
||||
{
|
||||
base.PerformIndexItems(values, onComplete);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -433,7 +433,7 @@ namespace Umbraco.Cms.Core.Scoping
|
||||
|
||||
if (this != _scopeProvider.AmbientScope)
|
||||
{
|
||||
var failedMessage = $"The {nameof(Scope)} {this.GetDebugInfo()} being disposed is not the Ambient {nameof(Scope)} {_scopeProvider.AmbientScope.GetDebugInfo()}. This typically indicates that a child {nameof(Scope)} was not disposed or flowed to a child thread that was not re-joined to the thread that the parent originated (i.e. Task.Run used as a fire and forget task without ExecutionContext.SuppressFlow()).";
|
||||
var failedMessage = $"The {nameof(Scope)} {this.GetDebugInfo()} being disposed is not the Ambient {nameof(Scope)} {_scopeProvider.AmbientScope.GetDebugInfo()}. This typically indicates that a child {nameof(Scope)} was not disposed, or flowed to a child thread that was not awaited, or concurrent threads are accessing the same {nameof(Scope)} (Ambient context) which is not supported. If using Task.Run (or similar) as a fire and forget tasks or to run threads in parallel you must suppress execution context flow with ExecutionContext.SuppressFlow() and ExecutionContext.RestoreFlow().";
|
||||
|
||||
#if DEBUG_SCOPES
|
||||
Scope ambient = _scopeProvider.AmbientScope;
|
||||
|
||||
@@ -129,12 +129,12 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping
|
||||
Console.WriteLine("Child Task after disposed: " + scopeProvider.AmbientScope.InstanceId);
|
||||
});
|
||||
|
||||
Thread.Sleep(2000); // block for a bit to ensure the child task is disposed first
|
||||
Console.WriteLine("Parent Task waiting: " + scopeProvider.AmbientScope?.InstanceId);
|
||||
Task.WaitAll(t);
|
||||
Console.WriteLine("Parent Task disposing: " + scopeProvider.AmbientScope.InstanceId);
|
||||
mainScope.Dispose();
|
||||
Console.WriteLine("Parent Task disposed: " + scopeProvider.AmbientScope?.InstanceId);
|
||||
|
||||
Task.WaitAll(t);
|
||||
Assert.Pass();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user