aspnetcore: Concurrency Exception While Rendering Razor Page
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
I am seeing an intermittent exception being thrown in production. It does not appear to involve my code, but occurs when rendering my _Host.cshtml
. I have not seen this until recently and may be due to a NuGet update to 7.0.10
.
Expected Behavior
No response
Steps To Reproduce
This is an intermittent exception that has occurred twice now. Unfortunately I am not sure what causes it. As the call stack does not contain any of my custom code I am reporting it here for next steps.
Note that this occurs while rendering a component
tag:
<component type="typeof(Starbeam.Integration.Crisp.Presentation.IdentifierContainer)" render-mode="ServerPrerendered" />
Exceptions (if any)
System.InvalidOperationException: Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.
at ref TValue System.Collections.Generic.Dictionary<TKey, TValue>.FindValue(TKey key)
at bool System.Collections.Generic.Dictionary<TKey, TValue>.TryGetValue(TKey key, out TValue value)
at IUrlHelper Microsoft.AspNetCore.Mvc.Routing.UrlHelperFactory.GetUrlHelper(ActionContext context)
at bool Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper.TryResolveUrl(string url, out IHtmlContent resolvedUrl)
at void Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper.ProcessUrlAttribute(string attributeName, TagHelperOutput output)
at void Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper.Process(TagHelperContext context, TagHelperOutput output)
at Task Microsoft.AspNetCore.Razor.TagHelpers.TagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output)
at Task Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.RunAsync(TagHelperExecutionContext executionContext)
at async Task Starbeam.Applications.Gateway.Pages.Pages__Host.ExecuteAsync()+(?) => { } in C:/agent/default/_work/1/s/starbeam.one/Pages/_Host.cshtml:line 84
at async Task Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext.SetOutputContentAsync()
at async Task Starbeam.Applications.Gateway.Pages.Pages__Host.ExecuteAsync()
at async Task Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
at async Task<ViewBufferTextWriter> Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, bool invokeViewStarts)
at async Task Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
at async Task Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, int? statusCode) x 2
at async Task Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultAsync(IActionResult result)+Logged(?)
at async Task Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeNextResultFilterAsync<TFilter, TFilterAsync>()+Awaited(?)
at void Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
at Task Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext<TFilter, TFilterAsync>(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
at async Task Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()+Awaited(?)
at async Task Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeNextResourceFilter()+Awaited(?)
at void Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Task Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
at async Task Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()+Awaited(?)
at async Task Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeAsync()+Logged(?) x 2
at async Task Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)+AwaitRequestTask(?)
at async Task Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at async Task Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at async Task<bool> Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT<TContext>.ProcessRequestAsync()
.NET Version
8.0.100-preview.7.23376.3 locally but 7.0.10
on the projects
Anything else?
Thank you for all the amazing work out there. 😃
About this issue
- Original URL
- State: open
- Created 10 months ago
- Reactions: 1
- Comments: 17 (1 by maintainers)
We have solved the problem! It is not related to NET7. We have a Serilog custom enricher to manage our correlation ids. We made a change to store the correlation id in the HttpContext.Items collection due to performance reasons, but seems not to be a good idea. Is it possible to make this collection compatible with multi-threading scenarios?
Glad you were able to figure it out, @marcmarsinach. Unfortunately, I do not have anything obvious like this in my solution and I do not make use of the
HttpContext.Items
anywhere in my custom code.So in my case, this appears to be a Very Badâ„¢ environmental/configuration-based issue that I continue to track down.
Same problem here after upgrade to .NET7 from .NET6