From 85415a695e88c5b38cf280c14ee93453198471b1 Mon Sep 17 00:00:00 2001 From: Fredrik Rombach Ekelund Date: Wed, 21 Jan 2026 14:41:54 +0100 Subject: [PATCH 1/2] Avoid `failure` event when deliberately killing events subscriber --- src/modules/cli/lib/cli-events-subscriber.ts | 27 ++++++++++---------- src/modules/cli/lib/execute-command.ts | 9 ++++++- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/modules/cli/lib/cli-events-subscriber.ts b/src/modules/cli/lib/cli-events-subscriber.ts index e83e57a3b3..ae0ee65c4d 100644 --- a/src/modules/cli/lib/cli-events-subscriber.ts +++ b/src/modules/cli/lib/cli-events-subscriber.ts @@ -5,17 +5,6 @@ import { sendIpcEventToRenderer } from 'src/ipc-utils'; import { executeCliCommand } from 'src/modules/cli/lib/execute-command'; import { SiteServer } from 'src/site-server'; -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; - function siteDetailsToServerDetails( site: SiteDetails, running: boolean, @@ -70,6 +59,18 @@ const handleSiteEvent = sequential( async ( event: SiteEvent ): Promise< void > void sendIpcEventToRenderer( 'site-event', event ); } ); +// Hello +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; + export async function startCliEventsSubscriber(): Promise< void > { return new Promise( ( resolve, reject ) => { if ( subscriber ) { @@ -111,8 +112,8 @@ export async function startCliEventsSubscriber(): Promise< void > { export function stopCliEventsSubscriber(): void { if ( subscriber ) { - const [ , childProcess ] = subscriber; + const [ eventEmitter, childProcess ] = subscriber; + eventEmitter.removeAllListeners(); childProcess.kill( 'SIGKILL' ); - subscriber = null; } } diff --git a/src/modules/cli/lib/execute-command.ts b/src/modules/cli/lib/execute-command.ts index 49cd5e1634..478cb6123d 100644 --- a/src/modules/cli/lib/execute-command.ts +++ b/src/modules/cli/lib/execute-command.ts @@ -107,7 +107,14 @@ export function executeCliCommand( function appQuitHandler() { const pid = child.pid; const result = child.kill(); - console.log( `Child process with pid ${ pid } killed with result: ${ result }` ); + if ( result ) { + console.log( `Successfully killed child process with pid ${ pid }` ); + } else { + console.error( + `Failed to kill child process with pid ${ pid }. This likely means the process is already terminated. CLI args:`, + args + ); + } } child.on( 'close', ( code ) => { From 4294940dfac1225d52bd06319cad8d05a9c531ce Mon Sep 17 00:00:00 2001 From: Fredrik Rombach Ekelund Date: Wed, 21 Jan 2026 14:46:24 +0100 Subject: [PATCH 2/2] Stray comment --- src/modules/cli/lib/cli-events-subscriber.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/cli/lib/cli-events-subscriber.ts b/src/modules/cli/lib/cli-events-subscriber.ts index ae0ee65c4d..55a0a8a46a 100644 --- a/src/modules/cli/lib/cli-events-subscriber.ts +++ b/src/modules/cli/lib/cli-events-subscriber.ts @@ -59,7 +59,6 @@ const handleSiteEvent = sequential( async ( event: SiteEvent ): Promise< void > void sendIpcEventToRenderer( 'site-event', event ); } ); -// Hello const cliSiteEventSchema = z.object( { action: z.literal( 'keyValuePair' ), key: z.literal( 'site-event' ),