Skip to content

Commit 737ad56

Browse files
author
Deploy Bot
committed
fix(cli-v3): ensure worker cleanup on SIGINT/SIGTERM (#2909)
1 parent 8b684e1 commit 737ad56

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/cli-v3": patch
3+
---
4+
5+
Fix: `trigger.dev dev` command left orphaned worker processes when exited via Ctrl+C (SIGINT). Added signal handlers to ensure proper cleanup of child processes and lockfiles. (#2909)

packages/cli-v3/src/commands/dev.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,22 +171,38 @@ export async function devCommand(options: DevCommandOptions) {
171171
);
172172
} else {
173173
logger.log(
174-
`${chalkError("X Error:")} You must login first. Use the \`login\` CLI command.\n\n${
175-
authorization.error
174+
`${chalkError("X Error:")} You must login first. Use the \`login\` CLI command.\n\n${authorization.error
176175
}`
177176
);
178177
}
179178
process.exitCode = 1;
180179
return;
181180
}
182181

183-
let watcher;
182+
let devInstance: Awaited<ReturnType<typeof startDev>> | undefined;
183+
184+
const cleanup = async () => {
185+
if (devInstance) {
186+
await devInstance.stop();
187+
}
188+
};
189+
190+
const signalHandler = async (signal: string) => {
191+
logger.debug(`Received ${signal}, cleaning up...`);
192+
await cleanup();
193+
process.exit(0);
194+
};
195+
184196
try {
185-
const devInstance = await startDev({ ...options, cwd: process.cwd(), login: authorization });
186-
watcher = devInstance.watcher;
197+
process.on("SIGINT", signalHandler);
198+
process.on("SIGTERM", signalHandler);
199+
200+
devInstance = await startDev({ ...options, cwd: process.cwd(), login: authorization });
187201
await devInstance.waitUntilExit();
188202
} finally {
189-
await watcher?.stop();
203+
process.off("SIGINT", signalHandler);
204+
process.off("SIGTERM", signalHandler);
205+
await cleanup();
190206
}
191207
}
192208

@@ -272,7 +288,7 @@ async function startDev(options: StartDevOptions) {
272288

273289
devInstance = await bootDevSession(watcher.config);
274290

275-
const waitUntilExit = async () => {};
291+
const waitUntilExit = async () => { };
276292

277293
return {
278294
watcher,

0 commit comments

Comments
 (0)