aboutsummaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-10-16 12:54:42 -0700
committerAdam Soltys <[email protected]>2026-10-16 12:54:42 -0700
commitb31437b5a77b371c7788993359553471692af4c6 (patch)
tree60e6cf577ec15ade79e1a706362fc0cabd74d724 /bridge
parent04b395feba38e50506174c03fa537911d3f15459 (diff)
downloadcoinosv3-server-b31437b5a77b371c7788993359553471692af4c6.tar.gz
coinosv3-server-b31437b5a77b371c7788993359553471692af4c6.zip
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 <[email protected]>
Diffstat (limited to 'bridge')
-rw-r--r--bridge/ln.js8
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'));