Skip to content

Commit 2b65f6d

Browse files
committed
Clean out dead processes so we don't endlessly wait for them
1 parent 711f4ef commit 2b65f6d

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

integrationTests/utils/loopbackAddressPool.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff 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
*

0 commit comments

Comments
 (0)