oops, forgot commit

This commit is contained in:
Shannon
2021-03-09 17:50:43 +11:00
parent a668e9aa07
commit 0b6d99c23a
3 changed files with 18 additions and 4 deletions

View File

@@ -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);
}
}
}

View File

@@ -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;

View File

@@ -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();
}