Skip to content

Fixed race condition in the disposing of the QuickGrid #62840

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

Merged
merged 8 commits into from
Jul 28, 2025

Conversation

dariatiurina
Copy link
Contributor

Fixed race condition in the disposing of the QuickGrid

Description

This pull request introduces changes to improve the disposal logic of the QuickGrid component and adds new tests to ensure proper handling of race conditions during disposal. It also updates project files to include new test dependencies and internal visibility settings. Below is a summary of the most important changes:

Changes:

  • Added a _disposeBool flag to the QuickGrid component to track its disposal state and prevent further operations if disposal is in progress.
  • Updated the DisposeAsync method to set _disposeBool to true and ensure proper cleanup of resources.
  • Modified the OnAfterRenderAsync method to check the _disposeBool flag and exit early if the component is being disposed while the JavaScript module is loading.
  • Introduced a new test class, GridRaceConditionTest, to verify that the QuickGrid component can handle race conditions during disposal without errors. This includes simulating JavaScript interop behavior and rendering scenarios.
  • Added InternalsVisibleTo for Microsoft.AspNetCore.Components.QuickGrid.Tests in the Microsoft.AspNetCore.Components.csproj file to allow internal access for testing purposes.
  • Updated the Microsoft.AspNetCore.Components.QuickGrid.Tests.csproj file to include shared test helpers and dependencies for the new tests.

Fixes #47173

@github-actions github-actions bot added the area-blazor Includes: Blazor, Razor Components label Jul 21, 2025
@dariatiurina dariatiurina self-assigned this Jul 22, 2025
@wtgodbe
Copy link
Member

wtgodbe commented Jul 22, 2025

/azp run

Copy link

Azure Pipelines successfully started running 4 pipeline(s).

@dariatiurina dariatiurina marked this pull request as ready for review July 24, 2025 14:24
@Copilot Copilot AI review requested due to automatic review settings July 24, 2025 14:24
@dariatiurina dariatiurina requested a review from a team as a code owner July 24, 2025 14:24
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a race condition in the QuickGrid component that could occur when the component is disposed while a JavaScript module is still being loaded. The fix adds a disposal flag to prevent JavaScript operations from executing after disposal has begun.

  • Adds a _wasDisposed boolean flag to track disposal state and prevent operations after disposal
  • Updates the disposal and rendering logic to handle race conditions gracefully
  • Introduces comprehensive tests to verify the fix works and demonstrates the original problem

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
QuickGrid.razor.cs Adds _wasDisposed flag and disposal race condition protection
GridRaceConditionTest.cs New test class with comprehensive race condition testing
NotFailingQuickGrid.cs Test helper component that uses the fixed QuickGrid implementation
FailingQuickGrid.cs Test helper component that simulates the original race condition bug
Microsoft.AspNetCore.Components.csproj Adds internal visibility for QuickGrid tests
Microsoft.AspNetCore.Components.QuickGrid.Tests.csproj Includes shared test helpers
Comments suppressed due to low confidence (1)

src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/QuickGrid.razor.cs:156

  • [nitpick] The field name _wasDisposed should be _disposeBool to match the variable name referenced in the PR description and test code, ensuring consistency across the codebase.
    private bool _wasDisposed;

Copy link
Member

@ilonatommy ilonatommy left a comment

Choose a reason for hiding this comment

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

Great job!

Only a few clean-up updates.

@ilonatommy ilonatommy added this to the 10.0-rc1 milestone Jul 25, 2025
dariatiurina and others added 2 commits July 25, 2025 09:51
…Grid/test/GridRaceConditionTest.cs

Co-authored-by: Ilona Tomkowicz <[email protected]>
@ilonatommy ilonatommy merged commit 1202a8f into dotnet:main Jul 28, 2025
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QuickGrid has a race condition with disposal during init
3 participants