Fixing race in distributed cache tag helper

Fixes #4407
This commit is contained in:
Sébastien Ros 2016-04-06 09:42:24 -07:00
parent c66c408c15
commit efb8ef33e6
3 changed files with 13 additions and 13 deletions

View File

@ -147,21 +147,21 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers.Cache
}
}
}
// Notify all other awaiters of the final content
tcs.TrySetResult(content);
}
catch
{
// Notify all other awaiters to render the content
tcs.TrySetResult(null);
content = null;
throw;
}
finally
{
// Remove the worker task from the in-memory cache
Task<IHtmlContent> worker;
_workers.TryRemove(key, out worker);
// Remove the worker task before setting the result.
// If the result is null, other threads would potentially
// acquire it otherwise.
_workers.TryRemove(key, out result);
// Notify all other awaiters to render the content
tcs.TrySetResult(content);
}
}
else