File tree Expand file tree Collapse file tree 3 files changed +20
-8
lines changed
Expand file tree Collapse file tree 3 files changed +20
-8
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " trigger.dev " : patch
3+ ---
4+
5+ fix(dev): stop max listeners exceeded warning messages when running more than 10 runs concurrently
Original file line number Diff line number Diff 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 ( ) ;
Original file line number Diff line number Diff 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" ;
You can’t perform that action at this time.
0 commit comments