fix(admin): harden the boot DM — await a connected relay + guard teardown/rejection (#48, review CS-3) #49

Merged
padreug merged 2 commits from fix/boot-dm-await-connect into dev 2026-06-27 11:19:51 +00:00
Showing only changes of commit d8790087b4 - Show all commits

fix(admin): wait for a connected relay before the boot DM, not a fixed sleep (#48)
Some checks failed
Docker image / build-and-push-image (push) Has been cancelled

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, #45
Padreug 2026-06-27 12:03:27 +02:00

View file

@ -127,8 +127,15 @@ class AdminInterface {
const sk = secretKeyBytes(this.adminNsec); const sk = secretKeyBytes(this.adminNsec);
const pool = new RelayPool(['wss://blastr.f7z.xyz', 'wss://nostr.mutinywallet.com'], {}); const pool = new RelayPool(['wss://blastr.f7z.xyz', 'wss://nostr.mutinywallet.com'], {});
pool.start(); pool.start();
// Give the connections a moment to come up before publishing. // Wait until at least one relay is actually connected (capped), rather
await new Promise((r) => setTimeout(r, 2500)); // than a fixed sleep — these external public relays can be slow to come
// up, and a too-short fixed wait made the DM publish fail on boot. Still
// best-effort: if none connect in time we fall through and dmUser logs
// the publish failure without affecting the daemon. (#48)
const deadline = Date.now() + 8000;
while (pool.connectedCount() === 0 && Date.now() < deadline) {
await new Promise((r) => setTimeout(r, 100));
}
for (const npub of this.npubs || []) { for (const npub of this.npubs || []) {
await dmUser(sk, npub, `nsecBunker has started; use ${connectionString} to connect to it and unlock your key(s)`, pool); await dmUser(sk, npub, `nsecBunker has started; use ${connectionString} to connect to it and unlock your key(s)`, pool);