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

Fix possible crash navigating away from Dashboard #3619

Merged
merged 1 commit into from
Aug 16, 2024
Merged

Conversation

krschau
Copy link
Collaborator

@krschau krschau commented Aug 15, 2024

Summary of the pull request

If something terrible happens during Dashboard startup and the _initWidgetsCancellationTokenSource in not initialized, then cancelling it when we move away from the Dashboard can cause a crash. Check that the object is initialized before trying to use it.

References and relevant issues

Detailed description of the pull request / Additional comments

Validation steps performed

PR checklist

  • Closes #xxx
  • Tests added/passed
  • Documentation updated

@krschau krschau merged commit ad0726c into main Aug 16, 2024
4 checks passed
@krschau krschau deleted the user/krschau/cancel branch August 16, 2024 16:52
@@ -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?

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

Successfully merging this pull request may close these issues.

6 participants