Use async ChangeToken.OnChange overload in FileConfigurationProvider#130492
Open
svick wants to merge 2 commits into
Open
Use async ChangeToken.OnChange overload in FileConfigurationProvider#130492svick wants to merge 2 commits into
svick wants to merge 2 commits into
Conversation
Replace the blocking Thread.Sleep in the reload callback with an awaited Task.Delay, using the new async Func<Task> overload of ChangeToken.OnChange (dotnet#69099). This avoids blocking a thread for the duration of the reload delay. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 059bf1b8-31e2-4608-a038-210880f90d06
Contributor
|
Tagging subscribers to this area: @dotnet/area-extensions-configuration |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates FileConfigurationProvider’s file-change reload callback to use the async ChangeToken.OnChange overload and replace a blocking Thread.Sleep debounce with an awaited Task.Delay, aiming to avoid tying up a thread during the reload delay.
Changes:
- Replace
Thread.Sleep(Source.ReloadDelay)withawait Task.Delay(Source.ReloadDelay).ConfigureAwait(false)inside the reload callback. - Switch the callback passed to
ChangeToken.OnChangeto anasynclambda (binding to theFunc<Task>overload). - Update
usingdirectives accordingly (System.Threading→System.Threading.Tasks).
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.
Uses the new async (
Func<Task>) overload ofChangeToken.OnChange(see #69099) inFileConfigurationProvider.The reload callback previously blocked a thread for the whole reload delay via
Thread.Sleep(Source.ReloadDelay). It nowawaitsTask.Delay(...)instead, so no thread is blocked while waiting out the debounce delay before reloading:Why only this call site
The other in-repo callers of
ChangeToken.OnChange(ConfigurationRoot,ConfigurationManager,OptionsMonitor) invoke short, synchronous, non-blocking consumers (RaiseChanged/InvokeChanged) and gain nothing from the async overload, so they are intentionally left unchanged.A closely related change is at dotnet/aspnetcore#67732.
Note
This PR description was generated by GitHub Copilot.