[release/8.0] [Blazor] Fix hot reload memory leak#53928
Merged
Conversation
Fix of razor hotreload change token leak. This disposes the old change tokens after the ClearCache event or before overwriting. If something goes wrong and this isn't cleared before the next invocation of UpdateEndpoints on the razor data source, clear it and dispose of it then.
* Add unit test to confirm change token is disposed during razer hot reload. * Per Makinnon's feedback, switch to a callback model to create the wrapped disposable for this unit test. * Update src/Components/Endpoints/test/HotReloadServiceTests.cs --------- Co-authored-by: Mackinnon Buck <[email protected]>
halter73
approved these changes
Feb 10, 2024
javiercn
approved these changes
Feb 10, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix hot reload memory leak
Fixes an issue where a memory leak caused hot reload edits in Blazor Web apps to take an increasing amount of time over the course of a hot reload session.
Backport of #53750 and #53827
Description
There is a static
ClearCachemethod that is expected to be implemented by the hot reload extension model. This method was not being implemented for Blazor'sHotReloadService. This PR adds that callback and forwards it to the data source to dispose the last change token in a thread safe manner. The PR also cleans up a few other smaller missingDisposecalls for this scenario.Fixes #52757
Customer Impact
Without this fix, if customers make more than 15 or 20 hot reload edits in a single hot reload session for their Blazor Web app, hot reload edits grind to a halt until the application gets restarted. We've received significant customer feedback that this impacts their workflow.
Regression?
This bug is specific to Blazor Web apps, which are new in .NET 8.
Risk
The only changes introduced are those that allow the correct disposal of hot reload state, and functionality is otherwise unchanged. The fix was verified both locally and with automated tests.
Verification
Packaging changes reviewed?