From d8790087b4ff0bf7654333f99a2f83e468de76cd Mon Sep 17 00:00:00 2001 From: Padreug Date: Sat, 27 Jun 2026 12:03:27 +0200 Subject: [PATCH] fix(admin): wait for a connected relay before the boot DM, not a fixed sleep (#48) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/daemon/admin/index.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/daemon/admin/index.ts b/src/daemon/admin/index.ts index a54ad60..36764bb 100644 --- a/src/daemon/admin/index.ts +++ b/src/daemon/admin/index.ts @@ -127,8 +127,15 @@ class AdminInterface { const sk = secretKeyBytes(this.adminNsec); const pool = new RelayPool(['wss://blastr.f7z.xyz', 'wss://nostr.mutinywallet.com'], {}); pool.start(); - // Give the connections a moment to come up before publishing. - await new Promise((r) => setTimeout(r, 2500)); + // Wait until at least one relay is actually connected (capped), rather + // 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 || []) { await dmUser(sk, npub, `nsecBunker has started; use ${connectionString} to connect to it and unlock your key(s)`, pool);