From 7f60265b3e6890f7a58d003dc8ee178b62e01939 Mon Sep 17 00:00:00 2001 From: hiro Date: Wed, 13 Dec 2023 16:35:37 +0700 Subject: [PATCH 1/4] chore: Bump nitro to 0.1.27 to support api to kill process --- extensions/inference-nitro-extension/bin/version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/inference-nitro-extension/bin/version.txt b/extensions/inference-nitro-extension/bin/version.txt index 7db267292f..a2e1aa9d93 100644 --- a/extensions/inference-nitro-extension/bin/version.txt +++ b/extensions/inference-nitro-extension/bin/version.txt @@ -1 +1 @@ -0.1.26 +0.1.27 From 539f11e5838313b14654d59784275f9f5e33e2af Mon Sep 17 00:00:00 2001 From: hiro Date: Wed, 13 Dec 2023 16:35:59 +0700 Subject: [PATCH 2/4] feat: Add api to kill nitro --- .../inference-nitro-extension/src/module.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/extensions/inference-nitro-extension/src/module.ts b/extensions/inference-nitro-extension/src/module.ts index 4bfc63af76..ce18e653ba 100644 --- a/extensions/inference-nitro-extension/src/module.ts +++ b/extensions/inference-nitro-extension/src/module.ts @@ -15,6 +15,7 @@ const NITRO_HTTP_SERVER_URL = `http://${LOCAL_HOST}:${PORT}`; const NITRO_HTTP_LOAD_MODEL_URL = `${NITRO_HTTP_SERVER_URL}/inferences/llamacpp/loadmodel`; const NITRO_HTTP_UNLOAD_MODEL_URL = `${NITRO_HTTP_SERVER_URL}/inferences/llamacpp/unloadModel`; const NITRO_HTTP_VALIDATE_MODEL_URL = `${NITRO_HTTP_SERVER_URL}/inferences/llamacpp/modelstatus`; +const NITRO_HTTP_KILL_URL = `${NITRO_HTTP_SERVER_URL}/processmanager/destroy`; // The subprocess instance for Nitro let subprocess = null; @@ -188,9 +189,14 @@ async function validateModelStatus(): Promise { */ function killSubprocess(): Promise { if (subprocess) { - subprocess.kill(); - subprocess = null; - console.debug("Subprocess terminated."); + fetch(NITRO_HTTP_KILL_URL, { + method: "DELETE", + }).catch((err) => { + console.error(err); + subprocess.kill(); + subprocess = null; + return killSubprocess(); + }); } else { return kill(PORT, "tcp").then(console.log).catch(console.log); } @@ -207,9 +213,6 @@ async function checkAndUnloadNitro() { // Attempt to unload model return fetch(NITRO_HTTP_UNLOAD_MODEL_URL, { method: "GET", - headers: { - "Content-Type": "application/json", - }, }).catch((err) => { console.error(err); // Fallback to kill the port From 96fa392fbaffc530189baea3bc6293f631074ae0 Mon Sep 17 00:00:00 2001 From: hiro <22463238+vuonghoainam@users.noreply.github.com> Date: Wed, 13 Dec 2023 16:40:56 +0700 Subject: [PATCH 3/4] Update extensions/inference-nitro-extension/src/module.ts Co-authored-by: Louis --- extensions/inference-nitro-extension/src/module.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/inference-nitro-extension/src/module.ts b/extensions/inference-nitro-extension/src/module.ts index ce18e653ba..d69cba9c34 100644 --- a/extensions/inference-nitro-extension/src/module.ts +++ b/extensions/inference-nitro-extension/src/module.ts @@ -189,14 +189,14 @@ async function validateModelStatus(): Promise { */ function killSubprocess(): Promise { if (subprocess) { - fetch(NITRO_HTTP_KILL_URL, { + return fetch(NITRO_HTTP_KILL_URL, { method: "DELETE", }).catch((err) => { console.error(err); subprocess.kill(); subprocess = null; - return killSubprocess(); - }); + return kill(PORT, "tcp").then(console.log).catch(console.log); +}); } else { return kill(PORT, "tcp").then(console.log).catch(console.log); } From 257011309f1ca9f3325e49afe6834cb8b1181b03 Mon Sep 17 00:00:00 2001 From: hiro Date: Wed, 13 Dec 2023 16:46:49 +0700 Subject: [PATCH 4/4] fix: Kill nitro many times app onDispose --- .../inference-nitro-extension/src/module.ts | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/extensions/inference-nitro-extension/src/module.ts b/extensions/inference-nitro-extension/src/module.ts index d69cba9c34..1c4b23fde9 100644 --- a/extensions/inference-nitro-extension/src/module.ts +++ b/extensions/inference-nitro-extension/src/module.ts @@ -188,18 +188,15 @@ async function validateModelStatus(): Promise { * @returns A Promise that resolves when the subprocess is terminated successfully, or rejects with an error message if the subprocess fails to terminate. */ function killSubprocess(): Promise { - if (subprocess) { - return fetch(NITRO_HTTP_KILL_URL, { - method: "DELETE", - }).catch((err) => { - console.error(err); - subprocess.kill(); - subprocess = null; - return kill(PORT, "tcp").then(console.log).catch(console.log); -}); - } else { - return kill(PORT, "tcp").then(console.log).catch(console.log); - } + fetch(NITRO_HTTP_KILL_URL, { + method: "DELETE", + }).catch((err) => { + console.error(err); + subprocess?.kill(); + kill(PORT, "tcp").then(console.log).catch(console.log); + subprocess = null; + }); + return } /**