(port: number, host: string, avoid: Set<number>)
| 100 | */ |
| 101 | private static SeqNumber = 0; |
| 102 | public static isPortInUseEx(port: number, host: string, avoid: Set<number>): Promise<boolean> { |
| 103 | const seq = TcpPortScanner.SeqNumber++; |
| 104 | const tries = TcpPortScanner.getLocalHostAliases(); |
| 105 | // We could have launched all tests at once and waited on a Promise.all but that fails on Linux |
| 106 | // Have seen cases where it steps on itself. In the same try, it will give an EADDRINUSE and a listen |
| 107 | // will succeed. Doing one at a time avoids that but that Linux behavior is strange indeed |
| 108 | return new Promise<boolean> (async (resolve) => { |
| 109 | if (avoid && avoid.has(port)) { |
| 110 | resolve(true); |
| 111 | return; |
| 112 | } |
| 113 | for (const host of tries) { |
| 114 | try { |
| 115 | const inUse = await TcpPortScanner.isPortInUse(port, host, seq); |
| 116 | if (inUse) { |
| 117 | resolve(true); |
| 118 | return; |
| 119 | } |
| 120 | } |
| 121 | catch (e) { |
| 122 | resolve(true); |
| 123 | return; |
| 124 | } |
| 125 | } |
| 126 | resolve(false); |
| 127 | }); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Scan for free ports (no one listening) on the specified host. |
no test coverage detected