libp2p / go-libp2p-pubsub

The PubSub implementation for go-libp2p
https://github.com/libp2p/specs/tree/master/pubsub
Other
323 stars 187 forks source link

topic.Close() and PeerLeave event #504

Closed D4ryl00 closed 1 year ago

D4ryl00 commented 1 year ago

Is it normal that when a peer closes a topic in a pubsub (with topic.Close()), the other peers on the same topic do not receive a PeerLeave event from the EventHandler of that topic? The problem is that when the peer joins the same topic after closing, the other peers do not receive a PeerJoin event. Thus, we cannot handle an action when this peer listens to the topic again.

On the other hand, if the peer closes connections with other peers, the peers receive the PeerLeave event. But in my case, I want to keep the connections because a peer can have more than one topic.

I wrote a snippet: https://gist.github.com/D4ryl00/ce34ff1289131b742ec4371f220269ba

D4ryl00 commented 1 year ago

The actual behavior is :

So to answer my question, we have to subscribe and cancel this subscription to receive the PeerLeave event. topic.Close() doesn't emit any event.

vyzo commented 1 year ago

what was the resolution?

vyzo commented 1 year ago

oh yes, of course. Thanks for the write up.