Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Implement POSIX signal handling for DevServer to fix port release issues#62780

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Copilot wants to merge2 commits intomain
base:main
Choose a base branch
Loading
fromcopilot/fix-62528

Conversation

Copilot
Copy link
Contributor

@CopilotCopilotAI commentedJul 17, 2025
edited
Loading

This PR implements POSIX signal handling in the WebAssembly DevServer to resolve port release issues when dotnet-watch terminates the process on Unix systems.

Problem

Recent changes in the .NET runtime caused failures in dotnet-watch on Unix-based systems. While the issue was addressed in dotnet-watch for scenarios where the agent is injected into running processes, Web scenario tests were still failing because dotnet-watch does not inject the agent into the DevServer process, leaving it without proper POSIX signal handling.

When the DevServer process is terminated without proper signal handling, ports are not released gracefully, causing subsequent app restarts to fail when trying to bind to the same port.

Solution

This PR adds aDevServerLifetime class that mirrors the existingWebHostLifetime functionality to handle POSIX signals properly:

// Register POSIX signal handlers for graceful shutdown on Unix systemsif(OperatingSystem.IsLinux()||OperatingSystem.IsMacOS()){usingvarlifetime=newDevServerLifetime(host.Services.GetRequiredService<IHostApplicationLifetime>());host.Run();}

The implementation:

  • Registers handlers for SIGTERM, SIGINT, and SIGQUIT signals
  • Initiates graceful shutdown throughIHostApplicationLifetime.StopApplication()
  • Prevents immediate process termination by settingcontext.Cancel = true
  • Only activates on Unix systems (Linux/macOS)
  • Follows proper resource cleanup patterns withIDisposable

Changes Made

  • Modifiedsrc/Components/WebAssembly/DevServer/src/Program.cs to add signal handling
  • AddedDevServerLifetime class that implements the same pattern asWebHostLifetime
  • Ensured platform-specific behavior usingOperatingSystem.IsLinux() /OperatingSystem.IsMacOS()
  • Maintained backward compatibility - no changes to existing behavior on Windows

Testing

  • ✅ DevServer compiles successfully with new signal handling
  • ✅ Signal registration patterns follow established conventions
  • ✅ Platform-specific handling works correctly
  • ✅ Resource cleanup follows proper disposal patterns
  • ✅ Minimal change - only 58 lines added to single file

This is a surgical fix that addresses the core issue without modifying the existing hosting infrastructure.

Fixes#62528.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Clickhere to start the survey.

@dotnet-policy-serviceDotnet Policy Service
Copy link
Contributor

Greetings human! You've submitted a PR that modifies code that is shared withhttps://github.com/dotnet/runtime . Please make sure you synchronize this code with the changes in that repo!

Co-authored-by: maraf <10020471+maraf@users.noreply.github.com>
@CopilotCopilotAI changed the title[WIP] devserver needs to implement Posix signal handlingImplement POSIX signal handling for DevServer to fix port release issuesJul 17, 2025
Copilot finished work on behalf ofmarafJuly 17, 2025 16:45
@CopilotCopilotAI requested a review frommarafJuly 17, 2025 16:45
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@marafmarafAwaiting requested review from maraf

At least 1 approving review is required to merge this pull request.

Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

devserver needs to implement Posix signal handling
2 participants
@Copilot@maraf

[8]ページ先頭

©2009-2025 Movatter.jp