Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fuzzy-ghosts-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---

fix(dev): stop max listeners exceeded warning messages when running more than 10 runs concurrently
15 changes: 15 additions & 0 deletions packages/cli-v3/src/dev/devSupervisor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,26 @@ class DevSupervisor implements WorkerRuntime {
//start an SSE connection for presence
this.disconnectPresence = await this.#startPresenceConnection();

// Handle SIGTERM to gracefully stop all run controllers
process.on("SIGTERM", this.#handleSigterm);

//start dequeuing
await this.#dequeueRuns();
}

#handleSigterm = async () => {
logger.debug("[DevSupervisor] Received SIGTERM, stopping all run controllers");

const stopPromises = Array.from(this.runControllers.values()).map((controller) =>
controller.stop()
);

await Promise.allSettled(stopPromises);
};

async shutdown(): Promise<void> {
process.off("SIGTERM", this.#handleSigterm);

this.disconnectPresence?.();
try {
this.socket?.close();
Expand Down
8 changes: 0 additions & 8 deletions packages/cli-v3/src/entryPoints/dev-run-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,8 @@ export class DevRunController {
logger.debug("[DevRunController] Failed to poll for snapshot", { error });
},
});

process.on("SIGTERM", this.sigterm.bind(this));
}

private async sigterm() {
logger.debug("[DevRunController] Received SIGTERM, stopping worker");
await this.stop();
}

// This should only be used when we're already executing a run. Attempt number changes are not allowed.
private updateRunPhase(run: Run, snapshot: Snapshot) {
Expand Down Expand Up @@ -856,8 +850,6 @@ export class DevRunController {
async stop() {
logger.debug("[DevRunController] Shutting down");

process.off("SIGTERM", this.sigterm);

if (this.taskRunProcess && !this.taskRunProcess.isBeingKilled) {
try {
const version = this.opts.worker.serverWorker?.version || "unknown";
Expand Down