diff options
| author | Adam Soltys <[email protected]> | 2026-11-20 01:55:55 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-11-20 01:55:55 -0700 |
| commit | 8ec9a1e70d7b43455c89768f27187f15d5983a38 (patch) | |
| tree | dd5b9387672b212da2df7c5a27ba91a3fb505a6a /bridge/ln.test.js | |
| parent | 6efa593d210370339c23c7cc01caa69a8dc233a5 (diff) | |
| download | coinosv3-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.test.js')
| -rw-r--r-- | bridge/ln.test.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/bridge/ln.test.js b/bridge/ln.test.js new file mode 100644 index 0000000..b9fb731 --- /dev/null +++ b/bridge/ln.test.js @@ -0,0 +1,48 @@ +import { test, expect } from 'bun:test'; +import { deadSocketWatch } from './ln.js'; + +const refused = Object.assign(new Error('connect ECONNREFUSED'), { code: 'ECONNREFUSED' }); +const rig = () => { + let t = 0, dead = 0; + const w = deadSocketWatch(() => dead++, { now: () => t }); + return { w, at: (ms) => { t = ms; }, dead: () => dead }; +}; + +test('a socket that worked, then refuses for a minute, is reported once', () => { + const r = rig(); + r.w.ok(); + r.at(1000); r.w.fail(refused); + r.at(30_000); r.w.fail(refused); + r.at(59_000); r.w.fail(refused); + expect(r.dead()).toBe(0); + r.at(62_000); r.w.fail(refused); + r.at(120_000); r.w.fail(refused); + expect(r.dead()).toBe(1); +}); + +test('a success in between starts the count again', () => { + const r = rig(); + r.w.ok(); + r.at(1000); r.w.fail(refused); + r.at(40_000); r.w.fail(refused); + r.at(50_000); r.w.ok(); + r.at(70_000); r.w.fail(refused); + r.at(80_000); r.w.fail(refused); + r.at(90_000); r.w.fail(refused); + expect(r.dead()).toBe(0); +}); + +test('a node that was never reached gets ten minutes', () => { + const r = rig(); + for (let t = 0; t < 590_000; t += 30_000) { r.at(t); r.w.fail(refused); } + expect(r.dead()).toBe(0); + r.at(601_000); r.w.fail(refused); + expect(r.dead()).toBe(1); +}); + +test('an error from the node itself is not a dead socket', () => { + const r = rig(); + r.w.ok(); + for (let t = 0; t < 300_000; t += 30_000) { r.at(t); r.w.fail(new Error('{"code":-1}')); } + expect(r.dead()).toBe(0); +}); |
