From e78d057f0f66cca45f0b967be6b9b55782484a83 Mon Sep 17 00:00:00 2001 From: Louis Date: Sat, 18 May 2024 14:14:56 +0700 Subject: [PATCH] fix: cortex process is not terminated properly (#2921) * chore: bump cortex-cpp to 0.4.6 * Bump cortex 0.4.7 --------- Co-authored-by: Van Pham <64197333+Van-QA@users.noreply.github.com> --- .../inference-nitro-extension/bin/version.txt | 2 +- .../src/node/index.ts | 20 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/extensions/inference-nitro-extension/bin/version.txt b/extensions/inference-nitro-extension/bin/version.txt index 6f2743d65..f90568270 100644 --- a/extensions/inference-nitro-extension/bin/version.txt +++ b/extensions/inference-nitro-extension/bin/version.txt @@ -1 +1 @@ -0.4.4 +0.4.7 diff --git a/extensions/inference-nitro-extension/src/node/index.ts b/extensions/inference-nitro-extension/src/node/index.ts index 03e172c63..1b24e0a38 100644 --- a/extensions/inference-nitro-extension/src/node/index.ts +++ b/extensions/inference-nitro-extension/src/node/index.ts @@ -50,7 +50,8 @@ const SUPPORTED_MODEL_FORMAT = '.gguf' let subprocess: ChildProcessWithoutNullStreams | undefined = undefined // The current model settings -let currentSettings: ModelSettingParams & { model?: string } | undefined = undefined +let currentSettings: (ModelSettingParams & { model?: string }) | undefined = + undefined /** * Stops a Nitro subprocess. @@ -153,7 +154,10 @@ async function loadModel( * 3. Validate model status * @returns */ -async function runNitroAndLoadModel(modelId: string, systemInfo?: SystemInformation) { +async function runNitroAndLoadModel( + modelId: string, + systemInfo?: SystemInformation +) { // Gather system information for CPU physical cores and memory return killSubprocess() .then(() => @@ -320,19 +324,23 @@ async function killSubprocess(): Promise { }) } - if (subprocess?.pid) { + if (subprocess?.pid && process.platform !== 'darwin') { log(`[CORTEX]::Debug: Killing PID ${subprocess.pid}`) const pid = subprocess.pid return new Promise((resolve, reject) => { terminate(pid, function (err) { if (err) { + log('[CORTEX]::Failed to kill PID - sending request to kill') killRequest().then(resolve).catch(reject) } else { tcpPortUsed .waitUntilFree(PORT, NITRO_PORT_FREE_CHECK_INTERVAL, 5000) - .then(() => resolve()) .then(() => log(`[CORTEX]::Debug: cortex process is terminated`)) + .then(() => resolve()) .catch(() => { + log( + '[CORTEX]::Failed to kill PID (Port check timeout) - sending request to kill' + ) killRequest().then(resolve).catch(reject) }) } @@ -358,9 +366,7 @@ function spawnNitroProcess(systemInfo?: SystemInformation): Promise { log( `[CORTEX]::Debug: Spawn cortex at path: ${executableOptions.executablePath}, and args: ${args}` ) - log( - path.parse(executableOptions.executablePath).dir - ) + log(path.parse(executableOptions.executablePath).dir) subprocess = spawn( executableOptions.executablePath, ['1', LOCAL_HOST, PORT.toString()],