Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Fix possible crash navigating away from Dashboard #3619

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private async Task OnLoadedAsync()
private async Task OnUnloadedAsync()
{
_log.Debug($"Unloading Dashboard, cancel any loading.");
_initWidgetsCancellationTokenSource.Cancel();
_initWidgetsCancellationTokenSource?.Cancel();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's still a race condition because InitializeDashboard() does some amount of non-trivial work before initializing _initWidgetsCancellationTokenSource. So it's possible that we could see this sequence:

  • OnLoadedAsync() called, InitializeDashboard() starts running, _initWidgetsCancellationTokenSource still null.
  • OnUnloadedAsync() called, _initWidgetsCancellationTokenSource still null, so no call to Cancel().
  • InitializeDashboard() finally reaches the point where it initializes _initWidgetsCancellationTokenSource, but because OnUnloadedAsync() is already finished, the cancellation never gets called.

Is there a reason we don't simply initialize the cancellation token in the constructor, so even in this case InitializeDashboard will eventually see the cancellation?

ViewModel.PinnedWidgets.CollectionChanged -= OnPinnedWidgetsCollectionChangedAsync;
Bindings.StopTracking();

Expand Down
Loading