From b31437b5a77b371c7788993359553471692af4c6 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 16 Oct 2026 12:54:42 -0700 Subject: bridge/ln: attach the socket error handler before connecting createConnection on a stale socket path threw ENOENT before a listener was attached and killed the process. Create the Socket, attach .on('error'), then connect. This was patched on the server and never committed. Co-Authored-By: Claude Opus 5.5 --- bridge/ln.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bridge/ln.js b/bridge/ln.js index cf2eab4..dce5254 100644 --- a/bridge/ln.js +++ b/bridge/ln.js @@ -7,7 +7,7 @@ // 'docker' — `docker exec lightning-cli` (regtest convenience) import { execFile } from 'node:child_process'; -import { createConnection } from 'node:net'; +import { Socket } from 'node:net'; const run = (cmd, args) => new Promise((resolve, reject) => { execFile(cmd, args, { maxBuffer: 8 << 20 }, (err, stdout, stderr) => { @@ -38,9 +38,13 @@ function socketAdapter({ path }) { return { call(method, params = {}) { return new Promise((resolve, reject) => { - const sock = createConnection(path); + // Listener before connect(): inside a Bun.serve handler, createConnection + // on a stale socket emits ENOENT before .on('error') is attached and the + // process dies with an uncaught exception. + const sock = new Socket(); let buf = ''; sock.on('error', reject); + sock.connect(path); sock.on('connect', () => sock.write(JSON.stringify({ jsonrpc: '2.0', id: ++id, method, params, }) + '\n')); -- cgit v1.2.3