Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit c29ca5a

Browse files
committed
fix: when peer is discovered but not online yet (racing cond), delay dial until libp2p is online
1 parent e91d142 commit c29ca5a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/core/components/libp2p.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@ module.exports = function libp2p (self) {
2525
self._libp2pNode = new Node(self._peerInfo, self._peerInfoBook, options)
2626

2727
self._libp2pNode.on('peer:discovery', (peerInfo) => {
28-
if (self.isOnline()) {
28+
const dial = () => {
2929
self._peerInfoBook.put(peerInfo)
3030
self._libp2pNode.dial(peerInfo, () => {})
3131
}
32+
if (self.isOnline()) {
33+
dial()
34+
} else {
35+
self._libp2pNode.once('online', dial)
36+
}
3237
})
3338

3439
self._libp2pNode.on('peer:connect', (peerInfo) => {

0 commit comments

Comments
 (0)