fix(cdp): clear socket timer on probe success; surface non-ENOENT readFile errors
amankumarsingh77 amankumarsingh7702@gmal.com
Sat, 02 May 2026 15:43:52 +0530
1 files changed,
10 insertions(+),
6 deletions(-)
jump to
M
src/cdp/discovery.ts
→
src/cdp/discovery.ts
@@ -38,16 +38,17 @@
const probePort = (port: number): Promise<Result<void, CdpError>> => new Promise((resolve) => { const sock = netConnect({ host: "127.0.0.1", port }); + let settled = false; const finish = (r: Result<void, CdpError>): void => { + if (settled) return; + settled = true; + sock.setTimeout(0); sock.destroy(); resolve(r); }; sock.setTimeout(1000, () => finish(err(cdpError("discovery_failed", "probe timeout")))); sock.once("error", (e) => finish(err(cdpError("discovery_failed", e.message)))); - sock.once("connect", () => { - sock.end(); - resolve(ok(undefined)); - }); + sock.once("connect", () => finish(ok(undefined))); }); const waitForPort = async (port: number): Promise<Result<void, CdpError>> => {@@ -72,8 +73,11 @@ const portFile = join(base, "DevToolsActivePort");
let raw: string; try { raw = await readFile(portFile, "utf8"); - } catch { - continue; + } catch (e) { + // Node fs errors carry .code; see ErrnoException + const code = (e as NodeJS.ErrnoException).code; + if (code === "ENOENT" || code === undefined) continue; + return err(cdpError("discovery_failed", `failed to read ${portFile}: ${e instanceof Error ? e.message : String(e)}`)); } const lines = raw.trim().split("\n"); if (lines.length < 2) continue;