Skip to content

Commit ea23888

Browse files
committed
fix(dev): stop max listeners exceeded warning messages when running more than 10 runs concurrently
1 parent e7fec40 commit ea23888

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

.changeset/fuzzy-ghosts-admire.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
fix(dev): stop max listeners exceeded warning messages when running more than 10 runs concurrently

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,26 @@ class DevSupervisor implements WorkerRuntime {
138138
//start an SSE connection for presence
139139
this.disconnectPresence = await this.#startPresenceConnection();
140140

141+
// Handle SIGTERM to gracefully stop all run controllers
142+
process.on("SIGTERM", this.#handleSigterm);
143+
141144
//start dequeuing
142145
await this.#dequeueRuns();
143146
}
144147

148+
#handleSigterm = async () => {
149+
logger.debug("[DevSupervisor] Received SIGTERM, stopping all run controllers");
150+
151+
const stopPromises = Array.from(this.runControllers.values()).map((controller) =>
152+
controller.stop()
153+
);
154+
155+
await Promise.allSettled(stopPromises);
156+
};
157+
145158
async shutdown(): Promise<void> {
159+
process.off("SIGTERM", this.#handleSigterm);
160+
146161
this.disconnectPresence?.();
147162
try {
148163
this.socket?.close();

packages/cli-v3/src/entryPoints/dev-run-controller.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,8 @@ export class DevRunController {
122122
logger.debug("[DevRunController] Failed to poll for snapshot", { error });
123123
},
124124
});
125-
126-
process.on("SIGTERM", this.sigterm.bind(this));
127125
}
128126

129-
private async sigterm() {
130-
logger.debug("[DevRunController] Received SIGTERM, stopping worker");
131-
await this.stop();
132-
}
133127

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

859-
process.off("SIGTERM", this.sigterm);
860-
861853
if (this.taskRunProcess && !this.taskRunProcess.isBeingKilled) {
862854
try {
863855
const version = this.opts.worker.serverWorker?.version || "unknown";

0 commit comments

Comments
 (0)