aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoramankumarsingh77 <amankumarsingh7702@gmal.com>2026-05-02 15:43:52 +0530
committeramankumarsingh77 <amankumarsingh7702@gmal.com>2026-05-02 15:43:52 +0530
commit73caf309809918730c9f11ee8f573301646fb1b6 (patch)
tree0720ab435c8507db8611019520430f509a5e177b /src
parent962ae3805c6ed7b38aa8153a145490a51df0097f (diff)
fix(cdp): clear socket timer on probe success; surface non-ENOENT readFile errors
Diffstat (limited to 'src')
-rw-r--r--src/cdp/discovery.ts16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/cdp/discovery.ts b/src/cdp/discovery.ts
index 1b33bee..8b35864 100644
--- a/src/cdp/discovery.ts
+++ b/src/cdp/discovery.ts
@@ -38,16 +38,17 @@ const profileDirs = (): ReadonlyArray<string> => {
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 @@ export const discoverWsUrl = async (): Promise<Result<string, CdpError>> => {
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;