From b913f2d4af218ae61de7073778feb56da89a15de Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Tue, 28 Jul 2026 22:08:16 +0530 Subject: refactor: daemon internals, and fix a leak the merge exposed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit IdMultiplexer and EventRouter were the only classes in src/; they are now createIdMultiplexer/createEventRouter closures like every other factory here. The multiplexer kept {clientId, localId} per daemon id while the bridge kept {send, clientId, localId, timer, isAttach} under the same key — two maps of overlapping data, and mux.resolve()'s return value was discarded at three of four call sites. One map now holds the union. That merge fixes a real leak: removeClient cleared the multiplexer but never the callbacks map, so a disconnected client's timers stayed armed and later fired a response at a socket that was gone. clearClient now cancels them, and a test pins it. handleRequest polled every 250ms for up to 15s per request when Chrome was down; N queued requests now await one connect signal. server.ts uses its own protocol's serialize/deserialize instead of hand-rolled JSON, and broadcast no longer routes through `this` — the only `this` in the codebase, and the one thing that breaks when the server object is destructured. cdp/event-queue.ts held two unrelated concerns; the request/timeout half moves to cdp/pending-requests.ts. cdp/daemon-transport.ts is the client half of the daemon protocol, so it moves to daemon/transport.ts. test/daemon/ needs adding to the test glob to run at all — there was no daemon test directory before because none of this was reachable without live Chrome. Co-Authored-By: Claude Opus 5 (1M context) --- test/cdp/event-queue-test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/cdp/event-queue-test.ts') diff --git a/test/cdp/event-queue-test.ts b/test/cdp/event-queue-test.ts index cae8143..771ce8e 100644 --- a/test/cdp/event-queue-test.ts +++ b/test/cdp/event-queue-test.ts @@ -1,6 +1,7 @@ import { test, describe } from "node:test"; import assert from "node:assert/strict"; -import { makeEventQueue, rejectAllPending, sendWithTimeout, type Pending } from "../../src/cdp/event-queue"; +import { makeEventQueue } from "../../src/cdp/event-queue"; +import { rejectAllPending, sendWithTimeout, type Pending } from "../../src/cdp/pending-requests"; describe("event queue iteration", () => { test("yields pushed events in order", async () => { -- cgit v1.2.3