aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAman Kumar <145339995+amankumarsingh77@users.noreply.github.com>2026-10-12 00:41:12 +0530
committerGitHub <noreply@github.com>2026-10-12 00:41:12 +0530
commit384688bf85ba5c806a40a059983f43ca537385cb (patch)
treeacef25ccbc047651e899132595ee34631c9c8ace /src
parent2601c90bc0ec54f1e6234d05112c99c458d4ae5e (diff)
fix(daemon): let pi exit after a session has connected to the daemon (#40)
The client's daemon socket is kept open across sessions by design; in pi -p it was the last handle keeping Node alive, so a run that had connected to the browser hung after its answer. Unref the socket; in-flight requests hold their own timers. Fixes #39 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Diffstat (limited to 'src')
-rw-r--r--src/daemon/transport.ts9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/daemon/transport.ts b/src/daemon/transport.ts
index 3c42336..b67610d 100644
--- a/src/daemon/transport.ts
+++ b/src/daemon/transport.ts
@@ -13,7 +13,7 @@ import {
serialize,
} from "./protocol";
-export const createDaemonTransport = (clientId: string): CdpTransport => {
+export const createDaemonTransport = (clientId: string, socketPath: string = DAEMON_SOCKET_PATH): CdpTransport => {
let socket: Socket | null = null;
let rl: ReturnType<typeof createInterface> | null = null;
let queue = makeEventQueue();
@@ -51,12 +51,17 @@ export const createDaemonTransport = (clientId: string): CdpTransport => {
let sock: Socket;
try {
- sock = createConnection(DAEMON_SOCKET_PATH);
+ sock = createConnection(socketPath);
} catch (e) {
settle(err(cdpError("transport_closed", e instanceof Error ? e.message : String(e))));
return;
}
socket = sock;
+ // The client is kept connected across sessions on purpose (index.ts session_shutdown), so this
+ // socket must not be what keeps the process alive: in `pi -p` it was the last handle standing
+ // and pi never exited (#39). In-flight requests hold their own ref'd timers, so nothing a
+ // caller is awaiting can be dropped by this.
+ sock.unref();
const connectTimer = setTimeout(() => {
cleanup("Connection timeout");