Fixes RecurringHostServices leaking the execution context / ambient scope (#12022)

As timers flow the execution context by default this resulted in the Ambient context scope being shared
This commit is contained in:
Vitor Rodrigues
2022-03-20 13:12:45 +01:00
parent defe9d432b
commit 18c2a18ec8
2 changed files with 19 additions and 1 deletions

View File

@@ -40,7 +40,18 @@ namespace Umbraco.Cms.Infrastructure.HostedServices
/// <inheritdoc/>
public Task StartAsync(CancellationToken cancellationToken)
{
_timer = new Timer(ExecuteAsync, null, (int)_delay.TotalMilliseconds, (int)_period.TotalMilliseconds);
if (!ExecutionContext.IsFlowSuppressed())
{
using (ExecutionContext.SuppressFlow())
{
_timer = new Timer(ExecuteAsync, null, (int)_delay.TotalMilliseconds, (int)_period.TotalMilliseconds);
}
}
else
{
_timer = new Timer(ExecuteAsync, null, (int)_delay.TotalMilliseconds, (int)_period.TotalMilliseconds);
}
return Task.CompletedTask;
}

View File

@@ -247,6 +247,13 @@ namespace Umbraco.Cms.Core.Services.Implement
/// </summary>
private bool TryDeserializeInstructions(CacheInstruction instruction, out JArray jsonInstructions)
{
if (instruction.Instructions == null)
{
_logger.LogError("Failed to deserialize instructions ({DtoId}: 'null').", instruction.Id);
jsonInstructions = null;
return false;
}
try
{
jsonInstructions = JsonConvert.DeserializeObject<JArray>(instruction.Instructions);