Skip to content

Refactor Hot Reload loop cancellation#53048

Merged
tmat merged 2 commits intodotnet:release/10.0.3xxfrom
tmat:ProcessCancellation
Feb 19, 2026
Merged

Refactor Hot Reload loop cancellation#53048
tmat merged 2 commits intodotnet:release/10.0.3xxfrom
tmat:ProcessCancellation

Conversation

@tmat
Copy link
Member

@tmat tmat commented Feb 15, 2026

Simplify and prepare for Aspire changes.

@tmat tmat changed the base branch from main to release/10.0.3xx February 15, 2026 21:02
@tmat tmat force-pushed the ProcessCancellation branch from e8e2831 to d0d1a1a Compare February 16, 2026 02:43
@tmat tmat marked this pull request as ready for review February 16, 2026 17:15
@tmat tmat requested a review from a team as a code owner February 16, 2026 17:15
Copilot AI review requested due to automatic review settings February 16, 2026 17:15
@tmat tmat changed the title Process cancellation Refactor Hot Reload loop cancellation Feb 16, 2026
Copy link
Contributor

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 refactors process cancellation handling in the dotnet-watch Hot Reload infrastructure. The main change is to simplify the lifecycle management of the processTerminationSource by moving its creation from being a parameter passed to launcher methods to being created internally within CompilationHandler.TrackRunningProjectAsync. This change reduces parameter coupling and makes the cancellation token lifecycle more encapsulated.

Changes:

  • Moved processTerminationSource creation from caller to CompilationHandler.TrackRunningProjectAsync with proper disposal
  • Simplified process exit code handling in ProcessRunner by consolidating signal-based termination detection
  • Added onExit callback in HotReloadDotNetWatcher to cancel iteration when root process exits
  • Added test coverage for Ctrl+R restart behavior during build and while waiting for file changes

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/BuiltInTools/Watch/Process/ProjectLauncher.cs Removed processTerminationSource parameter from TryLaunchProcessAsync
src/BuiltInTools/Watch/HotReload/CompilationHandler.cs Moved processTerminationSource creation inside TrackRunningProjectAsync and added to disposables
src/BuiltInTools/Watch/Aspire/AspireServiceFactory.cs Removed processTerminationSource variable and parameter
src/BuiltInTools/Watch/Process/ProcessRunner.cs Simplified exit code checking by consolidating OS-specific termination codes
src/BuiltInTools/Watch/Process/RunningProject.cs Updated comment to clarify auto-restart behavior
src/BuiltInTools/Watch/HotReload/HotReloadDotNetWatcher.cs Added onExit callback to cancel iteration on root process exit, simplified Hot Reload loop logic
src/BuiltInTools/Watch/UI/IReporter.cs Added new Restarting message descriptor
test/dotnet-watch.Tests/HotReload/RuntimeProcessLauncherTests.cs Removed parameter from test call, added two new tests for Ctrl+R restart scenarios
test/dotnet-watch.Tests/HotReload/ApplyDeltaTests.cs Added test identifiers to CombinatorialData tests for proper test isolation

@tmat tmat force-pushed the ProcessCancellation branch from e4b2c12 to 0ffc01d Compare February 16, 2026 17:23
@tmat
Copy link
Member Author

tmat commented Feb 17, 2026

@DustinCampbell ptal

Copy link
Member

@DustinCampbell DustinCampbell left a comment

Choose a reason for hiding this comment

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

Looks good to me.

extendTimeout = false;
// If the changes include addition/deletion wait a little bit more for possible matching deletion/addition.
// This eliminates reevaluations caused by teared add + delete of a temp file or a move of a file.
if (changedFilesAccumulator.Any(change => change.Kind is ChangeKind.Add or ChangeKind.Delete))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (changedFilesAccumulator.Any(change => change.Kind is ChangeKind.Add or ChangeKind.Delete))
if (changedFilesAccumulator.Any(static change => change.Kind is ChangeKind.Add or ChangeKind.Delete))

@tmat tmat merged commit 10359b4 into dotnet:release/10.0.3xx Feb 19, 2026
28 checks passed
@tmat tmat deleted the ProcessCancellation branch February 19, 2026 19:32
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.

3 participants