Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question on JSDisconnectedException and TaskCancelledException crashing app #395

Open
jakob-reesalu opened this issue Feb 4, 2025 · 5 comments

Comments

@jakob-reesalu
Copy link

jakob-reesalu commented Feb 4, 2025

Hi! We've suddenly found our application crashing due to various exceptions, two of which relate to BlazorGoogleMaps. IIS manages to restart things but we want to avoid crashes of course.

We use Blazor's ErrorBoundary to globally catch unexpected exceptions, but apparently these slip through somehow. From reading online, ErrorBoundary doesn't seem too reliable atm. So, we decided to wrap any calls using BlazorGoogleMaps in try-catch statements just to be on the safe side of things. We were just wondering though, should this be handled within the package itself? And, did anyone else see these kinds of issues?

These are picked up by Windows Event Viewer, they aren't showing up in our own log files:
JSDisconnectedException:

Description: The process was terminated due to an unhandled exception.
Exception Info: Microsoft.JSInterop.JSDisconnectedException: JavaScript interop calls cannot be issued at this time. This is because the circuit has disconnected and is being disposed.
   at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, CancellationToken cancellationToken, Object[] args)
   at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
   at GoogleMapsComponents.Helper.MyInvokeAsync[TRes](IJSRuntime jsRuntime, String identifier, Object[] args)
   at GoogleMapsComponents.Maps.Extension.ListableEntityListBase`2.SetMultipleAsync(Dictionary`2 opts, String googleMapListableEntityTypeName)
   at GoogleMapsComponents.Maps.Extension.MarkerList.SetMultipleAsync(Dictionary`2 opts)
   at GoogleMapsComponents.Maps.Extension.MarkerList.SyncAsync(MarkerList list, IJSRuntime jsRuntime, Dictionary`2 opts, Action`3 clickCallback)
...

TaskCancelledException:

Description: The process was terminated due to an unhandled exception.
Exception Info: Microsoft.JSInterop.JSDisconnectedException: JavaScript interop calls cannot be issued at this time. This is because the circuit has disconnected and is being disposed.
   at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, CancellationToken cancellationToken, Object[] args)
   at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
   at GoogleMapsComponents.Helper.MyInvokeAsync[TRes](IJSRuntime jsRuntime, String identifier, Object[] args)
   at GoogleMapsComponents.Maps.Extension.ListableEntityListBase`2.SetMultipleAsync(Dictionary`2 opts, String googleMapListableEntityTypeName)
   at GoogleMapsComponents.Maps.Extension.MarkerList.SetMultipleAsync(Dictionary`2 opts)
   at GoogleMapsComponents.Maps.Extension.MarkerList.SyncAsync(MarkerList list, IJSRuntime jsRuntime, Dictionary`2 opts, Action`3 clickCallback)
...

These examples concern MarkerList, but we see it for PolylineList and PolygonList as well.

@valentasm1
Copy link
Collaborator

Very interesting. Reproducible demo could help fix faster. Maybe you have one?

@jakob-reesalu
Copy link
Author

Hey, sorry for the slow response here! I got ill and was away from work. I don't have a reproducible demo unfortunately and I'm not skilled enough to throw something together quickly. JSDisconnectedException is a bit tricky because it happens when the circuit breaks between the browser and server, not sure how/if that can be reproduced in a demo?

@valentasm1
Copy link
Collaborator

Just random though. I was going through some component and saw that they handle JSDisconnectedException‎ explicitly.

https://github.com/vikramlearning/blazorbootstrap/blob/main/blazorbootstrap/Components/Collapse/Collapse.razor.cs#L23

@jakob-reesalu
Copy link
Author

jakob-reesalu commented Mar 3, 2025

What is random do you mean? That they handle JSDisconnectedException or that it is thrown? I searched in the code there, looks like they handle it consistently throughout. In BlazorGoogleMaps I notice it's catched at one place:

catch (Microsoft.JSInterop.JSDisconnectedException)

There's also this comment:

//Unfortunately, JSDisconnectedException is available in dotnet >= 6.0, and not in dotnet standard.

@valentasm1
Copy link
Collaborator

Random i mean that i just found on internet and i wanted to share. Not sure if it could be helpfull. Your examples in dispose method which happens when you leave page/component. In you case it could happen while you are one the page.
I dont think it is right approuch to handle exceptions on every call like in lib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants