Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Unix process termination #49374

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 2 commits into from
Jun 26, 2025
Merged

Unix process termination #49374

merged 2 commits into from
Jun 26, 2025

Conversation

tmat
Copy link
Member

@tmat tmat commented Jun 12, 2025

Multi-targets DotNetDeltaApplier in order to use Posix signal registration API. Register SIGTERM signal and exit the process. This is only needed for net10+ due to dotnet/docs#46226.

Since our startup hook is the first to execute in the app process, the registered handler will be the last to execute. See dotnet/runtime#116557.

The change also had to update WaitForExitAsync to avoid hangs on Unix. It's unclear why. The implementation of this API is generally unreliable, see dotnet/runtime#109434.

Blazor and WebApp tests still disabled. Needs more investigation.

@github-actions github-actions bot added the Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch label Jun 12, 2025
Copy link
Contributor

Thanks for your PR, @@tmat.
To learn about the PR process and branching schedule of this repo, please take a look at the SDK PR Guide.

@tmat tmat force-pushed the UnixProcessTermination branch from d58f47e to b5bf3f5 Compare June 12, 2025 20:21
@tmat tmat force-pushed the UnixProcessTermination branch 2 times, most recently from f54fe57 to 9bb9b15 Compare June 22, 2025 18:10
@tmat tmat force-pushed the UnixProcessTermination branch 2 times, most recently from 6d642dd to 787848e Compare June 24, 2025 22:48
@tmat tmat marked this pull request as ready for review June 24, 2025 23:10
@Copilot Copilot AI review requested due to automatic review settings June 24, 2025 23:10
@tmat tmat requested review from arunchndr and a team as code owners June 24, 2025 23:10
@tmat
Copy link
Member Author

tmat commented Jun 24, 2025

@DustinCampbell ptal

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 enhances Unix process termination and reliability for dotnet watch by multi-targeting the DeltaApplier, registering a SIGTERM handler, and improving WaitForExitAsync to avoid hangs. It also updates tests to be cross-platform and configures polling for file-watcher tests.

  • Add SIGTERM registration in the startup hook for graceful shutdown on Unix (net10+).
  • Refactor ProcessRunner.WaitForExitAsync with a polling loop to address hangs on Linux.
  • Enable polling file watcher in tests and remove Windows‐only [PlatformSpecificFact] attributes.

Reviewed Changes

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

Show a summary per file
File Description
test/.../WatchableApp.cs Add comment and enable polling file watcher in tests
test/.../ProgramTests.cs (and many) Replace [PlatformSpecificFact/Theory] with [Fact/Theory] for cross-platform tests
test/.../TestOptions.cs Use 1s timeout on Unix and 0s on Windows for process cleanup
test/TestAssets/.../AppWithDeps/Program.cs Increase loop delay from 10ms to 1000ms in test asset
src/.../dotnet-watch.csproj Multi-target Microsoft.Extensions.DotNetDeltaApplier for net10.0 and netstandard2.1
src/.../Internal/ProcessRunner.cs Refactor WaitForExitAsync to poll HasExited and log verbose messages
src/.../HotReload/StartupHook.cs Add RegisterPosixSignalHandlers to handle SIGTERM and exit process
Comments suppressed due to low confidence (1)

src/BuiltInTools/DotNetDeltaApplier/StartupHook.cs:86

  • No tests cover the new SIGTERM handler. Consider adding integration or unit tests to verify that the handler correctly triggers Environment.Exit(0) on Unix when SIGTERM is received.
    private static void RegisterPosixSignalHandlers()

@tmat tmat force-pushed the UnixProcessTermination branch from 7fb58e9 to e06e2ac Compare June 25, 2025 18:32
@tmat tmat enabled auto-merge (squash) June 25, 2025 20:37
@tmat tmat disabled auto-merge June 25, 2025 20:37
@tmat tmat force-pushed the UnixProcessTermination branch from e06e2ac to f0e9c2a Compare June 26, 2025 03:22
@tmat tmat merged commit 6142428 into dotnet:main Jun 26, 2025
26 checks passed
@tmat tmat deleted the UnixProcessTermination branch June 26, 2025 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants