From 9f6aac708b932484b4182330525c88a5ad23eed2 Mon Sep 17 00:00:00 2001 From: pompurin404 Date: Thu, 14 Nov 2024 19:47:59 +0800 Subject: [PATCH] fix find available port --- src/main/resolve/server.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/resolve/server.ts b/src/main/resolve/server.ts index d91e384..139e158 100644 --- a/src/main/resolve/server.ts +++ b/src/main/resolve/server.ts @@ -24,7 +24,6 @@ function FindProxyForURL(url, host) { export function findAvailablePort(startPort: number): Promise { return new Promise((resolve, reject) => { const server = net.createServer() - server.unref() server.on('error', (err) => { if (startPort <= 65535) { resolve(findAvailablePort(startPort + 1)) @@ -32,13 +31,12 @@ export function findAvailablePort(startPort: number): Promise { reject(err) } }) - - server.listen(startPort, () => { - // 端口可用 + server.on('listening', () => { server.close(() => { resolve(startPort) }) }) + server.listen(startPort, '127.0.0.1') }) }