Skip to content

Always kill PM2 daemon when running site stop --all#2683

Open
gcsecsey wants to merge 1 commit intotrunkfrom
gcsecsey/fix-pm2-stop-all
Open

Always kill PM2 daemon when running site stop --all#2683
gcsecsey wants to merge 1 commit intotrunkfrom
gcsecsey/fix-pm2-stop-all

Conversation

@gcsecsey
Copy link
Contributor

@gcsecsey gcsecsey commented Feb 27, 2026

Related issues

I ran into an issue while working on Studio from multiple workspaces. Each workspace has its own node_modules, and when the PM2 daemon was started from one workspace, it retained hardcoded paths to that workspace’s node_modules. When I switched to a different workspace (or the original one was removed/changed), the stale daemon would fail to fork child processes with MODULE_NOT_FOUND errors because those paths no longer existed.

Studio’s quit handler calls site stop --all, but if no sites are actively running at quit time, the command returns early without killing the PM2 daemon. The daemon would then linger with outdated module paths baked in, breaking subsequent launches from other workspaces.

Proposed Changes

  • Always call killDaemonAndChildrenAndExitProcess() when site stop --all is invoked, even if no sites are running
  • Updated test cases to verify daemon is killed in all scenarios

Testing Instructions

  • Start Studio and start some sites
  • Click the "Stop all" button
  • Check that the pm2 daemon is killed: npx pm2 list should show an empty table
  • Also check the same when closing Studio, and choosing "Stop sites" on the modal

Pre-merge Checklist

  • TypeScript and tests pass
  • No linting errors

When no sites are running, the daemon should still be killed to prevent
stale processes from persisting, particularly in development where the
daemon may retain hardcoded paths to node_modules that become invalid.
@gcsecsey gcsecsey requested a review from a team February 27, 2026 16:40
@gcsecsey gcsecsey changed the title Always kill PM2 daemon when running site stop --all Always kill PM2 daemon when running site stop --all Feb 27, 2026
@gcsecsey gcsecsey marked this pull request as ready for review February 27, 2026 16:43
Copy link
Contributor

@epeicher epeicher left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this @gcsecsey! I have been able to reproduce this on trunk by starting Studio and quickly quitting before the sites start. At that point, the pm2 processes are kept there. This is not happening on this branch, so this LGTM! :shipit:

Trunk This branch
Image Image

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change required?

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