fix(admin): harden the boot DM — await a connected relay + guard teardown/rejection (#48, review CS-3) #49
1 changed files with 9 additions and 2 deletions
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
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
commit
d8790087b4
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue