aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/ln.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-11-20 01:55:55 -0700
committerAdam Soltys <[email protected]>2026-11-20 01:55:55 -0700
commit8ec9a1e70d7b43455c89768f27187f15d5983a38 (patch)
treedd5b9387672b212da2df7c5a27ba91a3fb505a6a /bridge/ln.js
parent6efa593d210370339c23c7cc01caa69a8dc233a5 (diff)
downloadcoinosv3-server-8ec9a1e70d7b43455c89768f27187f15d5983a38.tar.gz
coinosv3-server-8ec9a1e70d7b43455c89768f27187f15d5983a38.zip
names restarts itself when the Lightning node's socket goes stale. "tried to zap pnk but it said names.coinos.io could not create an invoice" (Adam, 2026-11-20). bcln was recreated at 04:26Z; names has the node's socket file mounted, the mount kept pointing at the old file, and every @coinos.io LNURL invoice failed with ECONNREFUSED for four and a half hours until names was restarted by hand. The same thing cost 13 hours on 2026-11-11. The socket client now counts refused connections: after a minute of nothing but refusals (ten minutes if this process never reached the node, so a node that is down doesn't restart names in a loop) names logs it and exits, and docker's restart mounts the new socket. Only the mainnet node does this; the mutinynet one is left alone. New bridge/ln.test.js passes (4 checks), with the store and forget tests.
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01VMan6Upic5L6MMJzkTn8zg
Diffstat (limited to 'bridge/ln.js')
-rw-r--r--bridge/ln.js34
1 files changed, 30 insertions, 4 deletions
diff --git a/bridge/ln.js b/bridge/ln.js
index dce5254..7d1974c 100644
--- a/bridge/ln.js
+++ b/bridge/ln.js
@@ -33,8 +33,34 @@ function dockerAdapter({ container, network }) {
};
}
-function socketAdapter({ path }) {
+// A socket that refuses every call for a minute is not coming back by itself
+// when the socket FILE is bind-mounted into a container: lightningd makes a
+// new file when it restarts, and the mount still points at the old one. The
+// owner gets told through cfg.onDead (names exits there, and docker's restart
+// mounts the new file). `quiet` is how long before it may fire: a minute once
+// this process has reached the node, ten if it never has, so a node that is
+// simply down doesn't restart its client in a loop.
+export function deadSocketWatch(onDead, { streakMs = 60_000, coldMs = 600_000, now = Date.now } = {}) {
+ const born = now();
+ let since = 0, fails = 0, everUp = false, fired = false;
+ return {
+ ok() { everUp = true; since = 0; fails = 0; },
+ fail(err) {
+ if (!['ECONNREFUSED', 'ENOENT', 'ENOTSOCK'].includes(err?.code)) return;
+ const t = now();
+ if (!since) since = t;
+ fails++;
+ if (fired || fails < 3 || t - since < streakMs) return;
+ if (!everUp && t - born < coldMs) return;
+ fired = true;
+ onDead(err);
+ },
+ };
+}
+
+function socketAdapter({ path, onDead }) {
let id = 0;
+ const watch = onDead ? deadSocketWatch(onDead) : null;
return {
call(method, params = {}) {
return new Promise((resolve, reject) => {
@@ -43,11 +69,11 @@ function socketAdapter({ path }) {
// process dies with an uncaught exception.
const sock = new Socket();
let buf = '';
- sock.on('error', reject);
+ sock.on('error', (e) => { watch?.fail(e); reject(e); });
sock.connect(path);
- sock.on('connect', () => sock.write(JSON.stringify({
+ sock.on('connect', () => { watch?.ok(); sock.write(JSON.stringify({
jsonrpc: '2.0', id: ++id, method, params,
- }) + '\n'));
+ }) + '\n'); });
sock.on('data', (d) => {
buf += d;
let nl;