Skip to content

Avoid failure event when deliberately killing events subscriber#2443

Merged
wojtekn merged 2 commits intotrunkfrom
stu-1231-fix-cli-events-subscriber-log-message
Jan 21, 2026
Merged

Avoid failure event when deliberately killing events subscriber#2443
wojtekn merged 2 commits intotrunkfrom
stu-1231-fix-cli-events-subscriber-log-message

Conversation

@fredrikekelund
Copy link
Contributor

Related issues

Proposed Changes

The CLI _events child process is killed with a SIGKILL signal before the Electron app quits (see #2398 (comment) for background). This triggers a failure event on the CliCommandEventEmitter instance, which logs "CLI events subscriber exited unexpectedly" to stdout. This is misleading, because it didn't exit unexpectedly.

This PR fixes the problem by removing all event listeners from the CliCommandEventEmitter instance before sending the SIGKILL signal.

Testing Instructions

  1. Run npm start
  2. Add a line somewhere in the "back-end code" and save the file (a comment in src/index.ts, for example)
  3. Ensure that no CLI events subscriber exited unexpectedly is logged to stdout

Pre-merge Checklist

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

@fredrikekelund fredrikekelund requested a review from a team January 21, 2026 13:46
@fredrikekelund fredrikekelund self-assigned this Jan 21, 2026
Comment on lines +62 to +71
const cliSiteEventSchema = z.object( {
action: z.literal( 'keyValuePair' ),
key: z.literal( 'site-event' ),
value: z
.string()
.transform( ( val ) => JSON.parse( val ) )
.pipe( siteEventSchema ),
} );

let subscriber: ReturnType< typeof executeCliCommand > | null = null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just moved these definitions closer to where they're used

Comment on lines +113 to +116
console.error(
`Failed to kill child process with pid ${ pid }. This likely means the process is already terminated. CLI args:`,
args
);
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 is unrelated to the core purpose of this PR, but it will help us debug if there's ever an issue with unterminated child processes.

@wpmobilebot
Copy link
Collaborator

📊 Performance Test Results

Comparing 4294940 vs trunk

site-editor

Metric trunk 4294940 Diff Change
load 2865.00 ms 2870.00 ms +5.00 ms 🔴 0.2%

site-startup

Metric trunk 4294940 Diff Change
siteCreation 7091.00 ms 7112.00 ms +21.00 ms 🔴 0.3%
siteStartup 3946.00 ms 3947.00 ms +1.00 ms 🔴 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change

Copy link
Contributor

@wojtekn wojtekn left a comment

Choose a reason for hiding this comment

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

Works as expected.

@wojtekn wojtekn merged commit 8ae3110 into trunk Jan 21, 2026
11 checks passed
@wojtekn wojtekn deleted the stu-1231-fix-cli-events-subscriber-log-message branch January 21, 2026 15:33
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