Open jefft0 opened 1 year ago
Some background if it helps: We discovered and created a fix for this issue while working on this simple example of our networking library that is built on libp2p. https://wesh.network/posts/share-contact-and-send-message
Hello @vyzo . You suggested moving AddPeers
to inside startMonitoring
before the goroutine as p.AddPeers(p.host.Network().Peers()...)
. But with this change, TestSimpleDiscovery
hangs and times out. What do you suggest to do to resolve this? (Right now we have to use a fork of this repo with the fix.)
Uhm, fix the deadlock?
Maybe add an extra goroutine for startup.
This fixes a bug where another peer is not added to a topic after subscribing. This bug happens, for example, when a discovery system (like MDNS) is set up before pubsub initialization. Even though the peers have been discovered, they are not added to the new pubsub topics.
The bug can be seen by running TestNotifyPeerProtocolsUpdated in the master branch:
It prints "topic1 should at least have 1 peer". In our code we had to workaround this by disabling discovery (MDNS) and deferring discovery until after the pubsub protocols are registered. However, this pull request fixes the problem so that a workaround is not needed. It uses the event bus to monitor for peer connections and protocol updates. When
hosts[1]
joinstopic1
, the other peer is automatically added and the test passes.