From 525d58c1832ac83f93f96493a626dd41eb6b38c7 Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Tue, 9 Sep 2025 14:40:39 +0700 Subject: [PATCH 1/2] Improve shutdown handling for FwLiteWeb * Replace direct process killing with a dedicated `shutdownFwLite` function for graceful termination. * Update FwLiteWeb to properly handle `shutdown` commands via stdin. * Adjust process stdio configuration for consistency. --- backend/FwLite/FwLiteWeb/Program.cs | 8 ++++++++ platform.bible-extension/src/main.ts | 26 +++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/backend/FwLite/FwLiteWeb/Program.cs b/backend/FwLite/FwLiteWeb/Program.cs index e58a59753c..55020254ad 100644 --- a/backend/FwLite/FwLiteWeb/Program.cs +++ b/backend/FwLite/FwLiteWeb/Program.cs @@ -15,6 +15,14 @@ var url = app.Urls.First(); LocalAppLauncher.LaunchBrowser(url); } + //windows is dumb and so you can't send SIGINT to a process, so we need to listen for a shutdown command + _ = Task.Run(async () => + { + // Wait for the "shutdown" command from stdin + while (await Console.In.ReadLineAsync() is not "shutdown") { } + + await app.StopAsync(); + }); await app.WaitForShutdownAsync(); } diff --git a/platform.bible-extension/src/main.ts b/platform.bible-extension/src/main.ts index 9e4da9a21f..1aeae67b0f 100644 --- a/platform.bible-extension/src/main.ts +++ b/platform.bible-extension/src/main.ts @@ -249,7 +249,7 @@ export async function activate(context: ExecutionActivationContext): Promise fwLiteProcess?.kill(), + () => shutdownFwLite(fwLiteProcess), ); logger.info('FieldWorks Lite is finished activating!'); @@ -275,8 +275,7 @@ function launchFwLiteFwLiteWeb(context: ExecutionActivationContext) { context.executionToken, binaryPath, ['--urls', baseUrl, '--FwLiteWeb:OpenBrowser=false', '--FwLiteWeb:CorsAllowAny=true'], - // eslint-disable-next-line no-null/no-null - { stdio: [null, 'pipe', 'pipe'] }, + { stdio: ['pipe', 'pipe', 'pipe'] }, ); fwLiteProcess.once('exit', (code, signal) => { logger.info(`[FwLiteWeb]: exited with code '${code}', signal '${signal}'`); @@ -293,3 +292,24 @@ function launchFwLiteFwLiteWeb(context: ExecutionActivationContext) { } return { baseUrl, fwLiteProcess }; } + +function shutdownFwLite(fwLiteProcess: ReturnType['fwLiteProcess']): Promise { + return new Promise((resolve, reject) => { + fwLiteProcess.once('exit', (code, signal) => { + if (code === 0) { + resolve(true); + } else { + reject(new Error(`FwLiteWeb exited with code ${code}, signal ${signal}`)); + } + }); + fwLiteProcess.once('error', (error) => { + reject(error); + }); + + fwLiteProcess.stdin.write('shutdown\n'); + fwLiteProcess.stdin.end(); + setTimeout(() => { + fwLiteProcess.kill('SIGKILL'); + }, 10000); + }); +} From 032eea7d28c2a1264ce2ea1447ec62844f2345b8 Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Tue, 9 Sep 2025 14:52:37 +0700 Subject: [PATCH 2/2] never throw on shutdown, just log the error and return false --- platform.bible-extension/src/main.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/platform.bible-extension/src/main.ts b/platform.bible-extension/src/main.ts index 1aeae67b0f..630e0af563 100644 --- a/platform.bible-extension/src/main.ts +++ b/platform.bible-extension/src/main.ts @@ -294,22 +294,25 @@ function launchFwLiteFwLiteWeb(context: ExecutionActivationContext) { } function shutdownFwLite(fwLiteProcess: ReturnType['fwLiteProcess']): Promise { - return new Promise((resolve, reject) => { + return new Promise((resolve, _) => { fwLiteProcess.once('exit', (code, signal) => { if (code === 0) { resolve(true); } else { - reject(new Error(`FwLiteWeb exited with code ${code}, signal ${signal}`)); + logger.error(`[FwLiteWeb]: shutdown failed with code '${code}', signal '${signal}'`); + resolve(false); } }); fwLiteProcess.once('error', (error) => { - reject(error); + logger.error(`[FwLiteWeb]: shutdown failed with error: ${error}`); + resolve(false); }); fwLiteProcess.stdin.write('shutdown\n'); fwLiteProcess.stdin.end(); setTimeout(() => { fwLiteProcess.kill('SIGKILL'); + resolve(true); }, 10000); }); }