Skip to content

fix(chokidar, cli): fix orphaned child processes on intlayer watch exit#399

Merged
aymericzip merged 1 commit intoaymericzip:mainfrom
modanub:fix/watch-orphaned-processes
Mar 21, 2026
Merged

fix(chokidar, cli): fix orphaned child processes on intlayer watch exit#399
aymericzip merged 1 commit intoaymericzip:mainfrom
modanub:fix/watch-orphaned-processes

Conversation

@modanub
Copy link
Copy Markdown
Contributor

@modanub modanub commented Mar 21, 2026

Summary

When using intlayer watch --with '...', Ctrl+C kills the intlayer watcher but leaves the child process (e.g. Next.js/Turbopack) running in the background.

Three issues:

  • watch.ts checked 'child' in parallelProcess to kill the child on shutdown, but ParallelHandle doesn't have a child property — so the kill never ran. Fixed to use parallelProcess.kill().
  • Child processes were spawned without detached: true, so process.kill(-pid) couldn't target the process group. Fixed in spawnPosix.
  • spawnPosix used an async pidtree lookup to find descendant PIDs, but the parent called process.exit() before the callback fired. Replaced with synchronous process group kill.
  • Removed duplicate signal handlers from runParallel since callers already handle shutdown.

Test plan

  • intlayer watch --with 'exec next dev --turbopack' starts normally
  • Ctrl+C exits both intlayer and Next.js cleanly
  • No orphaned processes after exit

Use parallelProcess.kill() instead of checking for non-existent child
property. Spawn with detached: true on POSIX for proper process group
kill. Replace async pidtree with synchronous process group termination.
Copy link
Copy Markdown
Owner

@aymericzip aymericzip 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

thanks @modanub

@aymericzip aymericzip merged commit c30b4ce into aymericzip:main Mar 21, 2026
1 check passed
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.

2 participants