fix(admin): harden the boot DM — await a connected relay + guard teardown/rejection (#48, review CS-3) #49
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/boot-dm-await-connect"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #48; also folds in review finding CS-3.
The boot-time admin DM (
notifyAdminsOfNewConnection) opens a throwawayRelayPoolto two external public relays, then publishes. Two problems:1. Publish failed on boot (#48). It slept a fixed
2500msbefore publishing; those relays are often slower than that to connect, so on theaio-demodeploy the publish failed:Non-fatal (caught + logged; the daemon reached "ready to serve" and the spire was signing) but noisy every boot. Fix: poll
pool.connectedCount() > 0up to an 8s cap — send as soon as a relay is up, still best-effort.2. Leak + unhandled-rejection on a bad npub (review CS-3). The method had a bare
pool.start()/loop/pool.stop()with notry/finally, anddmUser'snip19.decode/nip04.encryptran before its publish-onlytry. A malformed adminnpub1…(passesstartsWith, fails the bech32 checksum) threw through the loop, skippingpool.stop()(leaking the pool's reconnect loops + sockets), and since the method is called from an un-.catch'd.thenin the constructor, the throw became an unhandled rejection — process-terminating under Node defaults. Fix:try/finally { pool.stop() }around the publish loop;.catchon the constructor's.then(both the notify and theconfig()it chains off);dmUsernow guards its whole body — best-effort, never throws.One-file-ish change (
admin/index.ts+utils/dm-user.ts).tscat baseline; daemon bundles; admin suite green.Refs: #48, #45; review CS-3
🤖 Generated with Claude Code
The boot-time admin notification (notifyAdminsOfNewConnection) spun up a throwaway RelayPool to two external public relays, slept a fixed 2500ms, then published. Those relays are often slow to connect, so on the aio-demo deploy the publish failed on boot ("relay not connected: wss://blastr.f7z.xyz; …") — caught and logged, non-fatal, but noisy every boot. Poll pool.connectedCount() > 0 up to an 8s cap instead: send as soon as a relay is up, and still best-effort — fall through and let dmUser log the failure if none connect in time. Refs: #48, #45fix(admin): wait for a connected relay before the boot DM, not a fixed sleep (#48)to fix(admin): harden the boot DM — await a connected relay + guard teardown/rejection (#48, review CS-3)