From d1944a556c423aa0b1b3710934a6f4f446a7b4b0 Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Mon, 1 Jun 2026 22:33:48 -0400 Subject: [PATCH] fix(contacts): time-box mesh join and friend topic link at boot Cap contacts hyperswarm join and _syncFriendTopicLinks so session startup cannot block forever. Co-authored-by: Cursor --- index.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 55f05e7..e23a4ea 100644 --- a/index.js +++ b/index.js @@ -480,13 +480,21 @@ class PearcordContacts extends EventEmitter { this.emit('peer', { peerId, type: 'leave' }) }) }) - await this.swarm.join(topicToBuffer(contactsTopic(this.userId)), { - server: true, - client: true - }) + const joinMs = Number(process.env.PEARCORD_MESH_JOIN_MS) || 8000 + await Promise.race([ + this.swarm.join(topicToBuffer(contactsTopic(this.userId)), { + server: true, + client: true + }), + new Promise((resolve) => setTimeout(resolve, joinMs)) + ]) await this._flushSwarm(3500) this._meshJoined = true - await this._syncFriendTopicLinks() + const linkMs = Number(process.env.PEARCORD_CONTACTS_FRIEND_LINK_MS) || 8000 + await Promise.race([ + this._syncFriendTopicLinks(), + new Promise((resolve) => setTimeout(resolve, linkMs)) + ]) if (this._lastSelfPresence) { await broadcastContactsGossip(this, RPC.PRESENCE_UPDATE, this._lastSelfPresence) }