From c4e6503b2578918c06a6df0b0de5af6a04134167 Mon Sep 17 00:00:00 2001 From: geekgeekrun Date: Sun, 27 Oct 2024 01:07:15 +0800 Subject: [PATCH] fix the issue that launchBossSite process is not exited when main process exited --- .../src/main/flow/LAUNCH_BOSS_SITE/index.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/ui/src/main/flow/LAUNCH_BOSS_SITE/index.ts b/packages/ui/src/main/flow/LAUNCH_BOSS_SITE/index.ts index e6834e2..deb560d 100644 --- a/packages/ui/src/main/flow/LAUNCH_BOSS_SITE/index.ts +++ b/packages/ui/src/main/flow/LAUNCH_BOSS_SITE/index.ts @@ -25,6 +25,7 @@ import { pipeWriteRegardlessError } from '../utils/pipe' import * as JSONStream from 'JSONStream' import { ChatStartupFrom } from '@geekgeekrun/sqlite-plugin/dist/entity/ChatStartupLog' import gtag from '../../utils/gtag' +import { sleep } from '@geekgeekrun/utils/sleep.mjs' const __dirname = url.fileURLToPath(new URL('.', import.meta.url)) const isRunFromUi = Boolean(process.env.MAIN_BOSSGEEKGO_UI_RUN_MODE) @@ -252,3 +253,23 @@ export async function launchBossSite() { await page.close() page = tempPage } + +// #region period check is parent process existed +// Store the parent process ID +const parentPID = process.ppid +// Function to check if the parent process is alive +async function periodCheckParentProcess() { + // eslint-disable-next-line no-constant-condition + while (true) { + try { + // Try sending signal 0 to the parent process (this does not terminate the process) + process.kill(parentPID, 0) + } catch (err) { + // If an error is thrown, the parent process doesn't exist anymore + process.exit(0) + } + await sleep(1000) + } +} +periodCheckParentProcess() +// #endregion