From 3960c80e9f55bdf41f9f257e12ed72c713577598 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" <37986729+carlos-r-l-rodrigues@users.noreply.github.com> Date: Thu, 25 Sep 2025 16:07:22 -0300 Subject: [PATCH] fix(medusa): start cluster (#13599) --- .changeset/thin-donkeys-vanish.md | 5 +++++ packages/medusa/src/commands/start.ts | 18 +++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 .changeset/thin-donkeys-vanish.md diff --git a/.changeset/thin-donkeys-vanish.md b/.changeset/thin-donkeys-vanish.md new file mode 100644 index 0000000000..fe4b286c31 --- /dev/null +++ b/.changeset/thin-donkeys-vanish.md @@ -0,0 +1,5 @@ +--- +"@medusajs/medusa": patch +--- + +fix(medusa): start cluster diff --git a/packages/medusa/src/commands/start.ts b/packages/medusa/src/commands/start.ts index 6a13cfeca6..c7e2239421 100644 --- a/packages/medusa/src/commands/start.ts +++ b/packages/medusa/src/commands/start.ts @@ -146,13 +146,13 @@ async function start(args: { }) { const { port = 9000, host, directory, types } = args - const container = await initializeContainer(directory, { - skipDbConnection: true, - }) - const logger = container.resolve(ContainerRegistrationKeys.LOGGER) - async function internalStart(generateTypes: boolean) { track("CLI_START") + + const container = await initializeContainer(directory, { + skipDbConnection: true, + }) + const logger = container.resolve(ContainerRegistrationKeys.LOGGER) await registerInstrumentation(directory) const app = express() @@ -270,13 +270,13 @@ async function start(args: { const killMainProccess = () => process.exit(0) const gracefulShutDown = () => { isShuttingDown = true - for (const id of Object.keys(cluster.workers ?? {})) { - cluster.workers?.[id]?.kill("SIGTERM") - } } for (let index = 0; index < numCPUs; index++) { - cluster.fork().send({ index }) + const worker = cluster.fork() + worker.on("online", () => { + worker.send({ index }) + }) } cluster.on("exit", () => {