Skip to content

fix: Kill child npm/ng processes when host process exits#74

Merged
PieterjanDeClippel merged 2 commits into
masterfrom
fix/kill-child-processes-on-exit
Mar 14, 2026
Merged

fix: Kill child npm/ng processes when host process exits#74
PieterjanDeClippel merged 2 commits into
masterfrom
fix/kill-child-processes-on-exit

Conversation

@PieterjanDeClippel

Copy link
Copy Markdown
Member

Summary

  • When stopping the VS debugger, the .NET host is terminated abruptly so IHostApplicationLifetime.ApplicationStopping never fires and the npm start / ng serve child processes become orphaned (ports remain occupied)
  • Adds ProcessTracker that uses a Windows Job Object with JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE so the OS automatically kills child processes when the parent handle closes — even on abrupt termination
  • Also registers an AppDomain.ProcessExit handler as a cross-platform fallback for graceful shutdowns

Test plan

  • Launch multiple SPA projects via VS debugger (e.g. Fleet, HR, SparkId)
  • Verify ng serve processes start and ports are accessible
  • Stop the debugger and confirm the ng serve processes are killed and ports are released
  • Verify normal dotnet run + Ctrl+C still cleans up properly

🤖 Generated with Claude Code

PieterjanDeClippel and others added 2 commits March 14, 2026 10:33
When stopping the VS debugger, the .NET host is terminated abruptly so
IHostApplicationLifetime.ApplicationStopping never fires and the npm/ng
serve child processes become orphaned.

Add ProcessTracker that uses a Windows Job Object with
JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE so the OS kills children when the
parent handle closes, even on abrupt termination. Also registers an
AppDomain.ProcessExit handler as a cross-platform fallback for graceful
shutdowns.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@PieterjanDeClippel PieterjanDeClippel merged commit d6b39c9 into master Mar 14, 2026
3 checks passed
@PieterjanDeClippel PieterjanDeClippel deleted the fix/kill-child-processes-on-exit branch March 14, 2026 09:39
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.

1 participant