Skip to content

Conversation

@fredrikekelund
Copy link
Contributor

Related issues

Proposed Changes

  • Add an AbortController in cli/lib/wordpress-server-manager.ts that interrupts sendMessage promises, ensuring that the CLI process exits when it receives a SIGINT or SIGTERM (Ctrl+C)
  • Add an abort IPC message topic that aborts async operations in cli/lib/types/wordpress-server-ipc.ts (most oftenly killing the process). We'll refine this behavior once Re-enable WP-CLI execution in the child process #2261 has landed.

Testing Instructions

  1. Run npm run cli:build
  2. Run node dist/cli/main.js site create --path PATH_TO_SITE where PATH_TO_SITE is the path to a new folder where the site should be created
  3. Once the process reaches the Starting WordPress server stage, press Ctrl+C
  4. Ensure that the process is aborted

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@fredrikekelund fredrikekelund self-assigned this Dec 18, 2025
Comment on lines -63 to -66
process.on( 'exit', disconnect );
process.on( 'SIGINT', disconnect );
process.on( 'SIGTERM', disconnect );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't necessary. API consumers should be responsible for connecting and disconnecting from pm2. In fact, this previously resulted in a race condition where the abort message I implemented in this PR wouldn't be delivered (because the process disconnected from the pm2 daemon before sending it).


const managerMessageStopServer = z.object( {
topic: z.literal( 'stop-server' ),
data: z.object( {} ),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

pm2 requires all messages to have id, topic, and data fields. We didn't notice that the stop-server topic would generate errors because stopWordPressServer swallows exceptions.

@fredrikekelund fredrikekelund changed the title [WIP] Ensure all CLI commands can be aborted Ensure all CLI commands can be aborted Dec 18, 2025
@fredrikekelund fredrikekelund changed the base branch from trunk to dev/studio-cli-i2 December 18, 2025 14:33
Copy link
Contributor

@bcotrim bcotrim left a comment

Choose a reason for hiding this comment

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

LGTM as works as described 👍

Image

@fredrikekelund fredrikekelund merged commit 4f3796a into dev/studio-cli-i2 Dec 19, 2025
3 of 5 checks passed
@fredrikekelund fredrikekelund deleted the f26d/cli-abort-async-operations branch December 19, 2025 10:07
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.

3 participants