Skip to content
This repository has been archived by the owner on Apr 21, 2022. It is now read-only.

Fix peer tagging #25

Closed
wants to merge 2 commits into from
Closed

Fix peer tagging #25

wants to merge 2 commits into from

Conversation

cannium
Copy link

@cannium cannium commented Nov 29, 2018

Another routine could observe event Connected earlier than ConnManager and tag peers, for now, those tags are lost.
Logs like tried to tag conn from untracked peer: <peer.ID Qm*3JXWfP> could be found.

Another routine could observe event `Connected` earlier than ConnManager
and tag peers, for now, those tags are lost.
@@ -164,8 +164,12 @@ func (cm *BasicConnMgr) TagPeer(p peer.ID, tag string, val int) {

pi, ok := cm.peers[p]
if !ok {
log.Info("tried to tag conn from untracked peer: ", p)
return
pi = &peerInfo{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, unfortunately, this will leak memory if we:

  1. Connect.
  2. Disconnect.
  3. Tag the peer.

A real fix will, unfortunately, require access to a Host and/or Network object (to check if we're currently connected. Unfortunately... that requires a much larger refactor (which is why I haven't bothered fixing this...).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But as long as Connect and Disconnect are paired, the calls from a rational caller to TagPeer and UntagPeer are paired. So maybe the situation is improved a little by this patch.

I'm not self-bloating, but you should really consider refactor the whole system like I said here: libp2p/go-libp2p#467 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But as long as Connect and Disconnect are paired, the calls from a rational caller to TagPeer and UntagPeer are paired. So maybe the situation is improved a little by this patch.

Not necessarily. Peers are sometimes tagged within Connect/Disconnect hooks but many services tag peers on an as-needed basis (and may never explicitly untag them). The expectation is that the connection manager will clean up any tags after a final disconnect.

@raulk
Copy link
Member

raulk commented May 27, 2019

I believe the effect this PR was trying to achieve was solved in #39 (buffering early tags). Please reopen if there’s still work to do.

@raulk raulk closed this May 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants