diff options
| -rw-r--r-- | bridge/ln.js | 8 |
1 files 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 <container> 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')); |
