File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -839,7 +839,12 @@ async function acquireWorker(): Promise<WorkerInfo | null> {
839839 const existing = selectWorker ( )
840840 if ( existing ) return existing
841841
842- const currentPoolSize = workers . size + spawnInProgress
842+ // Count only non-retiring workers toward pool occupancy so that a replacement
843+ // can be spawned pre-emptively while a retiring worker is still draining its
844+ // in-flight executions. Retiring workers stay in `workers` until they drain,
845+ // but they no longer accept new work, so they shouldn't block new spawns.
846+ const activeWorkerCount = [ ...workers . values ( ) ] . filter ( ( w ) => ! w . retiring ) . length
847+ const currentPoolSize = activeWorkerCount + spawnInProgress
843848 if ( currentPoolSize < POOL_SIZE ) {
844849 try {
845850 return await spawnWorker ( )
@@ -903,7 +908,11 @@ function dispatchToWorker(
903908 stdout : '' ,
904909 error : { message : 'Code execution failed to start. Please try again.' , name : 'Error' } ,
905910 } )
906- resetWorkerIdleTimeout ( workerInfo . id )
911+ if ( workerInfo . retiring && workerInfo . activeExecutions === 0 ) {
912+ cleanupWorker ( workerInfo . id )
913+ } else {
914+ resetWorkerIdleTimeout ( workerInfo . id )
915+ }
907916 // Defer to break synchronous recursion: drainQueue → dispatchToWorker → catch → drainQueue
908917 queueMicrotask ( ( ) => drainQueue ( ) )
909918 }
You can’t perform that action at this time.
0 commit comments