From 153ff839009e09eea907c5ec9746a890bd07f605 Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Thu, 18 Jun 2026 16:02:43 +0200 Subject: [PATCH 1/8] test log --- app/stores/back.js | 7 ++++++- app/stores/viewer.js | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/stores/back.js b/app/stores/back.js index 486adb6d..6fea5229 100644 --- a/app/stores/back.js +++ b/app/stores/back.js @@ -92,12 +92,17 @@ export const useBackStore = defineStore("back", { additionalProperties: true, }; const params = { COMMAND_BACK, NUXT_ROOT_PATH, args }; - + const start = Date.now() + console.log("[GEODE] PERF test begin launch", start) console.log("[GEODE] params", params); return appStore.request( { schema, params }, { response_function: (response) => { + const end = Date.now() + console.log("[GEODE] PERF test end launch", end) + console.log("[GEODE] PERF test diff", end - start) + console.log(`[GEODE] Back launched on port ${response.port}`); this.default_local_port = response.port; }, diff --git a/app/stores/viewer.js b/app/stores/viewer.js index e034a4da..2f1dc92a 100644 --- a/app/stores/viewer.js +++ b/app/stores/viewer.js @@ -143,11 +143,16 @@ export const useViewerStore = defineStore( const params = { COMMAND_VIEWER, NUXT_ROOT_PATH, args }; console.log("[VIEWER] params", params); - + const start = Date.now() + console.log("[VIEWER] PERF test begin launch", start) return appStore.request( { schema, params }, { response_function: (response) => { + const end = Date.now() + console.log("[VIEWER] PERF end launch", end) + console.log("[VIEWER] PERF test diff", end - start) + console.log(`[VIEWER] Viewer launched on port ${response.port}`); default_local_port.value = response.port; }, From 73de597f2548ee4beb84b1d7941f0cfe00c376ec Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Fri, 19 Jun 2026 11:16:55 +0200 Subject: [PATCH 2/8] fix(Perf): better microservices launch --- app/stores/back.js | 6 --- app/stores/viewer.js | 6 --- app/utils/local/microservices.js | 65 ++++++++++++++++------------- app/utils/local/scripts.js | 71 ++++++++++++++++++++++++++++---- 4 files changed, 100 insertions(+), 48 deletions(-) diff --git a/app/stores/back.js b/app/stores/back.js index 6fea5229..2dbacf6b 100644 --- a/app/stores/back.js +++ b/app/stores/back.js @@ -92,17 +92,11 @@ export const useBackStore = defineStore("back", { additionalProperties: true, }; const params = { COMMAND_BACK, NUXT_ROOT_PATH, args }; - const start = Date.now() - console.log("[GEODE] PERF test begin launch", start) console.log("[GEODE] params", params); return appStore.request( { schema, params }, { response_function: (response) => { - const end = Date.now() - console.log("[GEODE] PERF test end launch", end) - console.log("[GEODE] PERF test diff", end - start) - console.log(`[GEODE] Back launched on port ${response.port}`); this.default_local_port = response.port; }, diff --git a/app/stores/viewer.js b/app/stores/viewer.js index 2f1dc92a..92f084c0 100644 --- a/app/stores/viewer.js +++ b/app/stores/viewer.js @@ -143,16 +143,10 @@ export const useViewerStore = defineStore( const params = { COMMAND_VIEWER, NUXT_ROOT_PATH, args }; console.log("[VIEWER] params", params); - const start = Date.now() - console.log("[VIEWER] PERF test begin launch", start) return appStore.request( { schema, params }, { response_function: (response) => { - const end = Date.now() - console.log("[VIEWER] PERF end launch", end) - console.log("[VIEWER] PERF test diff", end - start) - console.log(`[VIEWER] Viewer launched on port ${response.port}`); default_local_port.value = response.port; }, diff --git a/app/utils/local/microservices.js b/app/utils/local/microservices.js index f5318311..8f106e46 100644 --- a/app/utils/local/microservices.js +++ b/app/utils/local/microservices.js @@ -8,13 +8,14 @@ import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.jso import { getPort } from "get-port-please"; import pTimeout from "p-timeout"; -// Local imports +// Local imports import { commandExistsSync, waitForReady } from "./scripts.js"; import { microservicesMetadatasPath, projectMicroservices } from "./cleanup.js"; import { executablePath } from "./path.js"; -const DEFAULT_TIMEOUT_SECONDS = 60; const MILLISECONDS_PER_SECOND = 1000; +const DEFAULT_TIMEOUT_SECONDS = 30; +const MAX_ERROR_BUFFER_BYTES = 64 * 1024; function getAvailablePort() { return getPort({ @@ -23,6 +24,13 @@ function getAvailablePort() { }); } +function resolveCommand(execPath, execName) { + const command = commandExistsSync(execName) + ? execName + : executablePath(execPath, execName); + return command; +} + async function runScript( execPath, execName, @@ -30,33 +38,32 @@ async function runScript( expectedResponse, timeoutSeconds = DEFAULT_TIMEOUT_SECONDS, ) { - let command = ""; - if (commandExistsSync(execName)) { - command = execName; - } else { - command = path.join(executablePath(execPath, execName)); - } + const command = resolveCommand(execPath, execName); console.log("runScript", command, args); - const child = child_process.spawn(process.platform === "win32" ? command : `"${command}"`, args, { - encoding: "utf8", - shell: true, + const child = child_process.spawn(command, args, { + stdio: ["ignore", "pipe", "pipe"], }); - child.stdout.on("data", (data) => console.log(`[${execName}] ${data.toString()}`)); - child.stderr.on("data", (data) => console.log(`[${execName}] ${data.toString()}`)); - child.on("close", (code) => console.log(`[${execName}] exited with code ${code}`)); - child.on("kill", () => { - console.log(`[${execName}] process killed`); - }); child.name = command.replace(/^.*[\\/]/u, ""); + child.on("spawn", () => { + console.log(`[${child.name}] spawned, pid=${child.pid}`); + }); + + const controller = new AbortController(); + const timer = setTimeout( + () => controller.abort(), + timeoutSeconds * MILLISECONDS_PER_SECOND, + ); + if (typeof timer.unref === "function") timer.unref(); + try { - return await pTimeout(waitForReady(child, expectedResponse), { - milliseconds: timeoutSeconds * MILLISECONDS_PER_SECOND, - message: `Timed out after ${timeoutSeconds} seconds`, - }); + const result = await waitForReady(child, expectedResponse, controller.signal); + clearTimeout(timer); + return result; } catch (error) { + clearTimeout(timer); child.kill(); throw error; } @@ -73,11 +80,11 @@ async function runBack(execName, execPath, args = {}) { } const port = await getAvailablePort(); const backArgs = [ - `--port ${port}`, - `--data_folder_path ${projectFolderPath}`, - `--upload_folder_path ${uploadFolderPath}`, - `--allowed_origin http://localhost:*`, - `--timeout ${0}`, + "--port", String(port), + "--data_folder_path", projectFolderPath, + "--upload_folder_path", uploadFolderPath, + "--allowed_origin", "http://localhost:*", + "--timeout", "0", ]; if (process.env.NODE_ENV === "development" || !process.env.NODE_ENV) { backArgs.push("--debug"); @@ -94,9 +101,9 @@ async function runViewer(execName, execPath, args = {}) { } const port = await getAvailablePort(); const viewerArgs = [ - `--port ${port}`, - `--data_folder_path ${projectFolderPath}`, - `--timeout ${0}`, + "--port", String(port), + "--data_folder_path", projectFolderPath, + "--timeout", "0", ]; console.log("runViewer", execPath, execName, viewerArgs); await runScript(execPath, execName, viewerArgs, "Starting factory"); diff --git a/app/utils/local/scripts.js b/app/utils/local/scripts.js index 954e5cf0..3fed4aca 100644 --- a/app/utils/local/scripts.js +++ b/app/utils/local/scripts.js @@ -3,9 +3,12 @@ import child_process from "node:child_process"; import fs from "node:fs"; import { on } from "node:events"; import path from "node:path"; +import readline from "node:readline"; import { appMode } from "./app_mode.js"; +const MAX_ERROR_BUFFER_BYTES = 64 * 1024; + function commandExistsSync(execName) { const envPath = process.env.PATH || ""; return envPath.split(path.delimiter).some((dir) => { @@ -14,13 +17,67 @@ function commandExistsSync(execName) { }); } -async function waitForReady(child, expectedResponse) { - for await (const [data] of on(child.stdout, "data")) { - if (data.toString().includes(expectedResponse)) { - return child; - } - } - throw new Error("Process closed before signal"); +function waitForReady(child, expectedResponse, signal) { + return new Promise((resolve, reject) => { + const rl = readline.createInterface({ input: child.stdout }); + const rlErr = readline.createInterface({ input: child.stderr }); + + let recentOutput = ""; + const recordOutput = (line) => { + recentOutput = (recentOutput + line + "\n").slice(-MAX_ERROR_BUFFER_BYTES); + }; + + const cleanup = () => { + rl.removeAllListeners(); + rl.close(); + rlErr.removeAllListeners(); + rlErr.close(); + child.removeListener("error", onError); + child.removeListener("close", onClose); + if (signal) signal.removeEventListener("abort", onAbort); + }; + + const onLine = (line) => { + console.log(`[${child.name}] ${line}`); + recordOutput(line); + if (line.includes(expectedResponse)) { + cleanup(); + resolve(child); + } + }; + + const onErrLine = (line) => { + console.log(`[${child.name}] ${line}`); + recordOutput(line); + }; + + const onError = (err) => { + cleanup(); + reject(err); + }; + + const onClose = (code) => { + console.log(`[${child.name}] exited with code ${code}`); + cleanup(); + reject( + new Error( + `[${child.name}] exited with code ${code} before becoming ready.` + + (recentOutput ? `\nRecent output:\n${recentOutput}` : ""), + ), + ); + }; + + const onAbort = () => { + cleanup(); + reject(new Error(`[${child.name}] timed out waiting for "${expectedResponse}"`)); + }; + + rl.on("line", onLine); + rlErr.on("line", onErrLine); + child.once("error", onError); + child.once("close", onClose); + if (signal) signal.addEventListener("abort", onAbort, { once: true }); + }); } async function waitNuxt(nuxtProcess) { From bf34b61b060ee5803dbe3351fdf577df315295ad Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Fri, 19 Jun 2026 16:59:45 +0200 Subject: [PATCH 3/8] fix(Perf): better microservices launch --- app/stores/back.js | 6 --- app/stores/viewer.js | 6 --- app/utils/local/microservices.js | 65 +++++++++++++++------------- app/utils/local/scripts.js | 72 ++++++++++++++++++++++++++++---- 4 files changed, 100 insertions(+), 49 deletions(-) diff --git a/app/stores/back.js b/app/stores/back.js index 6fea5229..2dbacf6b 100644 --- a/app/stores/back.js +++ b/app/stores/back.js @@ -92,17 +92,11 @@ export const useBackStore = defineStore("back", { additionalProperties: true, }; const params = { COMMAND_BACK, NUXT_ROOT_PATH, args }; - const start = Date.now() - console.log("[GEODE] PERF test begin launch", start) console.log("[GEODE] params", params); return appStore.request( { schema, params }, { response_function: (response) => { - const end = Date.now() - console.log("[GEODE] PERF test end launch", end) - console.log("[GEODE] PERF test diff", end - start) - console.log(`[GEODE] Back launched on port ${response.port}`); this.default_local_port = response.port; }, diff --git a/app/stores/viewer.js b/app/stores/viewer.js index 2f1dc92a..92f084c0 100644 --- a/app/stores/viewer.js +++ b/app/stores/viewer.js @@ -143,16 +143,10 @@ export const useViewerStore = defineStore( const params = { COMMAND_VIEWER, NUXT_ROOT_PATH, args }; console.log("[VIEWER] params", params); - const start = Date.now() - console.log("[VIEWER] PERF test begin launch", start) return appStore.request( { schema, params }, { response_function: (response) => { - const end = Date.now() - console.log("[VIEWER] PERF end launch", end) - console.log("[VIEWER] PERF test diff", end - start) - console.log(`[VIEWER] Viewer launched on port ${response.port}`); default_local_port.value = response.port; }, diff --git a/app/utils/local/microservices.js b/app/utils/local/microservices.js index f5318311..8f106e46 100644 --- a/app/utils/local/microservices.js +++ b/app/utils/local/microservices.js @@ -8,13 +8,14 @@ import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.jso import { getPort } from "get-port-please"; import pTimeout from "p-timeout"; -// Local imports +// Local imports import { commandExistsSync, waitForReady } from "./scripts.js"; import { microservicesMetadatasPath, projectMicroservices } from "./cleanup.js"; import { executablePath } from "./path.js"; -const DEFAULT_TIMEOUT_SECONDS = 60; const MILLISECONDS_PER_SECOND = 1000; +const DEFAULT_TIMEOUT_SECONDS = 30; +const MAX_ERROR_BUFFER_BYTES = 64 * 1024; function getAvailablePort() { return getPort({ @@ -23,6 +24,13 @@ function getAvailablePort() { }); } +function resolveCommand(execPath, execName) { + const command = commandExistsSync(execName) + ? execName + : executablePath(execPath, execName); + return command; +} + async function runScript( execPath, execName, @@ -30,33 +38,32 @@ async function runScript( expectedResponse, timeoutSeconds = DEFAULT_TIMEOUT_SECONDS, ) { - let command = ""; - if (commandExistsSync(execName)) { - command = execName; - } else { - command = path.join(executablePath(execPath, execName)); - } + const command = resolveCommand(execPath, execName); console.log("runScript", command, args); - const child = child_process.spawn(process.platform === "win32" ? command : `"${command}"`, args, { - encoding: "utf8", - shell: true, + const child = child_process.spawn(command, args, { + stdio: ["ignore", "pipe", "pipe"], }); - child.stdout.on("data", (data) => console.log(`[${execName}] ${data.toString()}`)); - child.stderr.on("data", (data) => console.log(`[${execName}] ${data.toString()}`)); - child.on("close", (code) => console.log(`[${execName}] exited with code ${code}`)); - child.on("kill", () => { - console.log(`[${execName}] process killed`); - }); child.name = command.replace(/^.*[\\/]/u, ""); + child.on("spawn", () => { + console.log(`[${child.name}] spawned, pid=${child.pid}`); + }); + + const controller = new AbortController(); + const timer = setTimeout( + () => controller.abort(), + timeoutSeconds * MILLISECONDS_PER_SECOND, + ); + if (typeof timer.unref === "function") timer.unref(); + try { - return await pTimeout(waitForReady(child, expectedResponse), { - milliseconds: timeoutSeconds * MILLISECONDS_PER_SECOND, - message: `Timed out after ${timeoutSeconds} seconds`, - }); + const result = await waitForReady(child, expectedResponse, controller.signal); + clearTimeout(timer); + return result; } catch (error) { + clearTimeout(timer); child.kill(); throw error; } @@ -73,11 +80,11 @@ async function runBack(execName, execPath, args = {}) { } const port = await getAvailablePort(); const backArgs = [ - `--port ${port}`, - `--data_folder_path ${projectFolderPath}`, - `--upload_folder_path ${uploadFolderPath}`, - `--allowed_origin http://localhost:*`, - `--timeout ${0}`, + "--port", String(port), + "--data_folder_path", projectFolderPath, + "--upload_folder_path", uploadFolderPath, + "--allowed_origin", "http://localhost:*", + "--timeout", "0", ]; if (process.env.NODE_ENV === "development" || !process.env.NODE_ENV) { backArgs.push("--debug"); @@ -94,9 +101,9 @@ async function runViewer(execName, execPath, args = {}) { } const port = await getAvailablePort(); const viewerArgs = [ - `--port ${port}`, - `--data_folder_path ${projectFolderPath}`, - `--timeout ${0}`, + "--port", String(port), + "--data_folder_path", projectFolderPath, + "--timeout", "0", ]; console.log("runViewer", execPath, execName, viewerArgs); await runScript(execPath, execName, viewerArgs, "Starting factory"); diff --git a/app/utils/local/scripts.js b/app/utils/local/scripts.js index 954e5cf0..d884e718 100644 --- a/app/utils/local/scripts.js +++ b/app/utils/local/scripts.js @@ -1,11 +1,13 @@ // Node imports -import child_process from "node:child_process"; import fs from "node:fs"; import { on } from "node:events"; import path from "node:path"; +import readline from "node:readline"; import { appMode } from "./app_mode.js"; +const MAX_ERROR_BUFFER_BYTES = 64 * 1024; + function commandExistsSync(execName) { const envPath = process.env.PATH || ""; return envPath.split(path.delimiter).some((dir) => { @@ -14,13 +16,67 @@ function commandExistsSync(execName) { }); } -async function waitForReady(child, expectedResponse) { - for await (const [data] of on(child.stdout, "data")) { - if (data.toString().includes(expectedResponse)) { - return child; - } - } - throw new Error("Process closed before signal"); +function waitForReady(child, expectedResponse, signal) { + return new Promise((resolve, reject) => { + const readlineStdout = readline.createInterface({ input: child.stdout }); + const readlineStderr = readline.createInterface({ input: child.stderr }); + + let recentOutput = ""; + const recordOutput = (line) => { + recentOutput = (recentOutput + line + "\n").slice(-MAX_ERROR_BUFFER_BYTES); + }; + + const cleanup = () => { + readlineStdout.removeAllListeners(); + readlineStdout.close(); + readlineStderr.removeAllListeners(); + readlineStderr.close(); + child.removeListener("error", onError); + child.removeListener("close", onClose); + if (signal) signal.removeEventListener("abort", onAbort); + }; + + const onLine = (line) => { + console.log(`[${child.name}] ${line}`); + recordOutput(line); + if (line.includes(expectedResponse)) { + cleanup(); + resolve(child); + } + }; + + const onErrLine = (line) => { + console.log(`[${child.name}] ${line}`); + recordOutput(line); + }; + + const onError = (err) => { + cleanup(); + reject(err); + }; + + const onClose = (code) => { + console.log(`[${child.name}] exited with code ${code}`); + cleanup(); + reject( + new Error( + `[${child.name}] exited with code ${code} before becoming ready.` + + (recentOutput ? `\nRecent output:\n${recentOutput}` : ""), + ), + ); + }; + + const onAbort = () => { + cleanup(); + reject(new Error(`[${child.name}] timed out waiting for "${expectedResponse}"`)); + }; + + readlineStdout.on("line", onLine); + readlineStderr.on("line", onErrLine); + child.once("error", onError); + child.once("close", onClose); + if (signal) signal.addEventListener("abort", onAbort, { once: true }); + }) } async function waitNuxt(nuxtProcess) { From 6f45181dada492e47b66b2df6ee5f11fd06b0fe9 Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Fri, 19 Jun 2026 17:02:50 +0200 Subject: [PATCH 4/8] cleanup --- app/stores/viewer.js | 1 + app/utils/local/microservices.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/stores/viewer.js b/app/stores/viewer.js index 92f084c0..e034a4da 100644 --- a/app/stores/viewer.js +++ b/app/stores/viewer.js @@ -143,6 +143,7 @@ export const useViewerStore = defineStore( const params = { COMMAND_VIEWER, NUXT_ROOT_PATH, args }; console.log("[VIEWER] params", params); + return appStore.request( { schema, params }, { diff --git a/app/utils/local/microservices.js b/app/utils/local/microservices.js index 8f106e46..76e8a9b9 100644 --- a/app/utils/local/microservices.js +++ b/app/utils/local/microservices.js @@ -8,7 +8,7 @@ import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.jso import { getPort } from "get-port-please"; import pTimeout from "p-timeout"; -// Local imports +// Local imports import { commandExistsSync, waitForReady } from "./scripts.js"; import { microservicesMetadatasPath, projectMicroservices } from "./cleanup.js"; import { executablePath } from "./path.js"; From 36ab4fcf37208ebe58f1b2446a1e0716de2aaed8 Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Fri, 19 Jun 2026 17:03:23 +0200 Subject: [PATCH 5/8] cleanup --- app/stores/back.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/stores/back.js b/app/stores/back.js index 2dbacf6b..486adb6d 100644 --- a/app/stores/back.js +++ b/app/stores/back.js @@ -92,6 +92,7 @@ export const useBackStore = defineStore("back", { additionalProperties: true, }; const params = { COMMAND_BACK, NUXT_ROOT_PATH, args }; + console.log("[GEODE] params", params); return appStore.request( { schema, params }, From 7ed999f01b1e948b868ded0c6929914a167a3fd7 Mon Sep 17 00:00:00 2001 From: JulienChampagnol <91873154+JulienChampagnol@users.noreply.github.com> Date: Fri, 19 Jun 2026 15:04:23 +0000 Subject: [PATCH 6/8] Apply prepare changes --- app/utils/local/microservices.js | 33 +++++++++++++++++--------------- app/utils/local/scripts.js | 4 ++-- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/app/utils/local/microservices.js b/app/utils/local/microservices.js index 76e8a9b9..b3ed8cde 100644 --- a/app/utils/local/microservices.js +++ b/app/utils/local/microservices.js @@ -25,9 +25,7 @@ function getAvailablePort() { } function resolveCommand(execPath, execName) { - const command = commandExistsSync(execName) - ? execName - : executablePath(execPath, execName); + const command = commandExistsSync(execName) ? execName : executablePath(execPath, execName); return command; } @@ -52,10 +50,7 @@ async function runScript( }); const controller = new AbortController(); - const timer = setTimeout( - () => controller.abort(), - timeoutSeconds * MILLISECONDS_PER_SECOND, - ); + const timer = setTimeout(() => controller.abort(), timeoutSeconds * MILLISECONDS_PER_SECOND); if (typeof timer.unref === "function") timer.unref(); try { @@ -80,11 +75,16 @@ async function runBack(execName, execPath, args = {}) { } const port = await getAvailablePort(); const backArgs = [ - "--port", String(port), - "--data_folder_path", projectFolderPath, - "--upload_folder_path", uploadFolderPath, - "--allowed_origin", "http://localhost:*", - "--timeout", "0", + "--port", + String(port), + "--data_folder_path", + projectFolderPath, + "--upload_folder_path", + uploadFolderPath, + "--allowed_origin", + "http://localhost:*", + "--timeout", + "0", ]; if (process.env.NODE_ENV === "development" || !process.env.NODE_ENV) { backArgs.push("--debug"); @@ -101,9 +101,12 @@ async function runViewer(execName, execPath, args = {}) { } const port = await getAvailablePort(); const viewerArgs = [ - "--port", String(port), - "--data_folder_path", projectFolderPath, - "--timeout", "0", + "--port", + String(port), + "--data_folder_path", + projectFolderPath, + "--timeout", + "0", ]; console.log("runViewer", execPath, execName, viewerArgs); await runScript(execPath, execName, viewerArgs, "Starting factory"); diff --git a/app/utils/local/scripts.js b/app/utils/local/scripts.js index d884e718..b5a2b6d0 100644 --- a/app/utils/local/scripts.js +++ b/app/utils/local/scripts.js @@ -61,7 +61,7 @@ function waitForReady(child, expectedResponse, signal) { reject( new Error( `[${child.name}] exited with code ${code} before becoming ready.` + - (recentOutput ? `\nRecent output:\n${recentOutput}` : ""), + (recentOutput ? `\nRecent output:\n${recentOutput}` : ""), ), ); }; @@ -76,7 +76,7 @@ function waitForReady(child, expectedResponse, signal) { child.once("error", onError); child.once("close", onClose); if (signal) signal.addEventListener("abort", onAbort, { once: true }); - }) + }); } async function waitNuxt(nuxtProcess) { From 8aa8ef77a0158f9ec3d12da7d457bf0e6109f3a5 Mon Sep 17 00:00:00 2001 From: JulienChampagnol Date: Fri, 19 Jun 2026 17:13:48 +0200 Subject: [PATCH 7/8] oxlint --- app/utils/local/microservices.js | 4 +++- app/utils/local/scripts.js | 24 +++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/utils/local/microservices.js b/app/utils/local/microservices.js index 76e8a9b9..02658934 100644 --- a/app/utils/local/microservices.js +++ b/app/utils/local/microservices.js @@ -15,7 +15,9 @@ import { executablePath } from "./path.js"; const MILLISECONDS_PER_SECOND = 1000; const DEFAULT_TIMEOUT_SECONDS = 30; -const MAX_ERROR_BUFFER_BYTES = 64 * 1024; +const BYTES_PER_KIBIBYTE = 1024; +const MAX_ERROR_BUFFER_KIBIBYTES = 64; +const MAX_ERROR_BUFFER_BYTES = MAX_ERROR_BUFFER_KIBIBYTES * BYTES_PER_KIBIBYTE; function getAvailablePort() { return getPort({ diff --git a/app/utils/local/scripts.js b/app/utils/local/scripts.js index d884e718..d9aad76f 100644 --- a/app/utils/local/scripts.js +++ b/app/utils/local/scripts.js @@ -6,12 +6,14 @@ import readline from "node:readline"; import { appMode } from "./app_mode.js"; -const MAX_ERROR_BUFFER_BYTES = 64 * 1024; +const BYTES_PER_KIBIBYTE = 1024; +const MAX_ERROR_BUFFER_KIBIBYTES = 64; +const MAX_ERROR_BUFFER_BYTES = MAX_ERROR_BUFFER_KIBIBYTES * BYTES_PER_KIBIBYTE; function commandExistsSync(execName) { const envPath = process.env.PATH || ""; - return envPath.split(path.delimiter).some((dir) => { - const filePath = path.join(dir, execName); + return envPath.split(path.delimiter).some((directory) => { + const filePath = path.join(directory, execName); return fs.existsSync(filePath) && fs.statSync(filePath).isFile(); }); } @@ -22,18 +24,18 @@ function waitForReady(child, expectedResponse, signal) { const readlineStderr = readline.createInterface({ input: child.stderr }); let recentOutput = ""; - const recordOutput = (line) => { + function recordOutput(line) { recentOutput = (recentOutput + line + "\n").slice(-MAX_ERROR_BUFFER_BYTES); }; - const cleanup = () => { + function cleanup() { readlineStdout.removeAllListeners(); readlineStdout.close(); readlineStderr.removeAllListeners(); readlineStderr.close(); child.removeListener("error", onError); child.removeListener("close", onClose); - if (signal) signal.removeEventListener("abort", onAbort); + if (signal) { signal.removeEventListener("abort", onAbort); } }; const onLine = (line) => { @@ -45,17 +47,17 @@ function waitForReady(child, expectedResponse, signal) { } }; - const onErrLine = (line) => { + function onErrLine(line) { console.log(`[${child.name}] ${line}`); recordOutput(line); }; - const onError = (err) => { + function onError(err) { cleanup(); reject(err); }; - const onClose = (code) => { + function onClose(code) { console.log(`[${child.name}] exited with code ${code}`); cleanup(); reject( @@ -66,7 +68,7 @@ function waitForReady(child, expectedResponse, signal) { ); }; - const onAbort = () => { + function onAbort() { cleanup(); reject(new Error(`[${child.name}] timed out waiting for "${expectedResponse}"`)); }; @@ -75,7 +77,7 @@ function waitForReady(child, expectedResponse, signal) { readlineStderr.on("line", onErrLine); child.once("error", onError); child.once("close", onClose); - if (signal) signal.addEventListener("abort", onAbort, { once: true }); + if (signal) { signal.addEventListener("abort", onAbort, { once: true }); } }) } From 05048151fa6fe2b6d6ed7d48e2ac734c58dfe941 Mon Sep 17 00:00:00 2001 From: JulienChampagnol <91873154+JulienChampagnol@users.noreply.github.com> Date: Fri, 19 Jun 2026 15:14:52 +0000 Subject: [PATCH 8/8] Apply prepare changes --- app/utils/local/scripts.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/utils/local/scripts.js b/app/utils/local/scripts.js index d9aad76f..7933f97f 100644 --- a/app/utils/local/scripts.js +++ b/app/utils/local/scripts.js @@ -26,7 +26,7 @@ function waitForReady(child, expectedResponse, signal) { let recentOutput = ""; function recordOutput(line) { recentOutput = (recentOutput + line + "\n").slice(-MAX_ERROR_BUFFER_BYTES); - }; + } function cleanup() { readlineStdout.removeAllListeners(); @@ -35,8 +35,10 @@ function waitForReady(child, expectedResponse, signal) { readlineStderr.close(); child.removeListener("error", onError); child.removeListener("close", onClose); - if (signal) { signal.removeEventListener("abort", onAbort); } - }; + if (signal) { + signal.removeEventListener("abort", onAbort); + } + } const onLine = (line) => { console.log(`[${child.name}] ${line}`); @@ -50,12 +52,12 @@ function waitForReady(child, expectedResponse, signal) { function onErrLine(line) { console.log(`[${child.name}] ${line}`); recordOutput(line); - }; + } function onError(err) { cleanup(); reject(err); - }; + } function onClose(code) { console.log(`[${child.name}] exited with code ${code}`); @@ -63,22 +65,24 @@ function waitForReady(child, expectedResponse, signal) { reject( new Error( `[${child.name}] exited with code ${code} before becoming ready.` + - (recentOutput ? `\nRecent output:\n${recentOutput}` : ""), + (recentOutput ? `\nRecent output:\n${recentOutput}` : ""), ), ); - }; + } function onAbort() { cleanup(); reject(new Error(`[${child.name}] timed out waiting for "${expectedResponse}"`)); - }; + } readlineStdout.on("line", onLine); readlineStderr.on("line", onErrLine); child.once("error", onError); child.once("close", onClose); - if (signal) { signal.addEventListener("abort", onAbort, { once: true }); } - }) + if (signal) { + signal.addEventListener("abort", onAbort, { once: true }); + } + }); } async function waitNuxt(nuxtProcess) {