jsakamoto / Toolbelt.Blazor.HeadElement

Head element support (change the document title, "meta" elements such as OGP, and "link" elements) for Blazor apps.
https://demo-blazor-headelement.azurewebsites.net/
Mozilla Public License 2.0
159 stars 11 forks source link

System.ObjectDisposedException showing up in Production Logs #27

Closed enusbaum closed 2 years ago

enusbaum commented 2 years ago

I'm seeing the following error show up in my Logs.

I'm unable to replicate it manually but I'm seeing it on my production site. The best I can guess, it's a timing issue where the client has navigated away from the page while OnParameterSetAsync() is still executing. I suspect this might be caused by a crawler bot quickly navigating the links on the site?

This is Blazor Server running on .NET 6 and HeadElement 6.0.2 hosted in Azure AppService.

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'JSObjectReference'.
   at Microsoft.JSInterop.Implementation.JSObjectReference.ThrowIfDisposed()
   at Microsoft.JSInterop.Implementation.JSObjectReference.InvokeAsync[TValue](String identifier, Object[] args)
   at Toolbelt.Blazor.HeadElement.HeadElementHelperService.InvokeJSAsync[T](String identifier, Object[] args)
   at Toolbelt.Blazor.HeadElement.HeadElementHelperService.GetDefaultTitleAsync()
   at Toolbelt.Blazor.HeadElement.HeadElementHelperService.GetDefaultsAsync()
   at Toolbelt.Blazor.HeadElement.HeadElementHelperService.ResetIfNeededAsync()
   at Toolbelt.Blazor.HeadElement.HeadElementHelperService.SetLinkElementsAsync(LinkElement[] elements)
   at Toolbelt.Blazor.HeadElement.Link.OnParametersSetAsync()
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
jsakamoto commented 2 years ago

@enusbaum Thanks for reporting!

I fixed this issue and published the new versions of these packages.

We can not avoid client disconnection while asynchronous processing, so I decided to treat this situation gracefully without any crashes.

Please check it out. 😄

enusbaum commented 2 years ago

Thanks! I can confirm after installing 7.0.0 I haven't seen the exception in my error logs in production.

I sincerely appreciate your maintaining this package as well as your swift response. Cheers! 🍻