File tree Expand file tree Collapse file tree 1 file changed +21
-3
lines changed
Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -289,12 +289,15 @@ export async function getNextAvailableLoopbackAddress(): Promise<string> {
289289 // Find the first available index
290290 const index = findAvailableIndex ( loopbackPool ) ;
291291
292- if ( index !== null ) {
292+ if ( index === null ) {
293+ // No available addresses - remove any dead processes from the pool and wait for one to become available
294+ removeDeadProcessesFromPool ( loopbackPool ) ;
295+ } else {
293296 // Assign the process PID to that index to mark it as used
294297 loopbackPool [ index ] = process . pid ;
295- // Write the updated pool back to the file
296- await writePoolFile ( loopbackPool ) ;
297298 }
299+ // Write the updated pool back to the file
300+ await writePoolFile ( loopbackPool ) ;
298301
299302 return index ;
300303 } ) ;
@@ -316,6 +319,21 @@ export async function getNextAvailableLoopbackAddress(): Promise<string> {
316319 }
317320}
318321
322+ /**
323+ * Removes any dead processes from the loopback pool.
324+ * @param loopbackPool
325+ */
326+ function removeDeadProcessesFromPool ( loopbackPool : LoopbackPool ) {
327+ loopbackPool . forEach ( ( pid , index ) => {
328+ if ( pid === null ) return ;
329+ try {
330+ process . kill ( pid , 0 ) ;
331+ } catch {
332+ loopbackPool [ index ] = null ;
333+ }
334+ } ) ;
335+ }
336+
319337/**
320338 * Releases a loopback address back to the pool, making it available for other processes.
321339 *
You can’t perform that action at this time.
0 commit comments