Skip to content

ERROR in fullrt/dht.go: key not found in map #1001

@lidel

Description

@lidel

Testing Kubo 0.32.1 with go-libp2p-kad-dht v0.28.1 revealed some ERROR messages in log:

Nov 18 16:01:36 kubo-staging-us-east-02 ipfs[573811]: 2024-11-18T16:01:36.870Z        ERROR        fullrtdht        fullrt/dht.go:450        key not found in map
Nov 18 16:01:36 kubo-staging-us-east-02 ipfs[573811]: 2024-11-18T16:01:36.870Z        ERROR        fullrtdht        fullrt/dht.go:450        key not found in map
Nov 18 16:01:36 kubo-staging-us-east-02 ipfs[573811]: 2024-11-18T16:01:36.905Z        ERROR        fullrtdht        fullrt/dht.go:450        key not found in map
Nov 18 16:01:36 kubo-staging-us-east-02 ipfs[573811]: 2024-11-18T16:01:36.906Z        ERROR        fullrtdht        fullrt/dht.go:450        key not found in map
Nov 18 16:01:36 kubo-staging-us-east-02 ipfs[573811]: 2024-11-18T16:01:36.952Z        ERROR        fullrtdht        fullrt/dht.go:450        key not found in map
Nov 18 16:01:36 kubo-staging-us-east-02 ipfs[573811]: 2024-11-18T16:01:36.953Z        ERROR        fullrtdht        fullrt/dht.go:450        key not found in map
Nov 18 16:01:36 kubo-staging-us-east-02 ipfs[573811]: 2024-11-18T16:01:36.953Z        ERROR        fullrtdht        fullrt/dht.go:450        key not found in map
Nov 18 16:01:36 kubo-staging-us-east-02 ipfs[573811]: 2024-11-18T16:01:36.963Z        ERROR        fullrtdht        fullrt/dht.go:450        key not found in map
Nov 18 16:01:36 kubo-staging-us-east-02 ipfs[573811]: 2024-11-18T16:01:36.963Z        ERROR        fullrtdht        fullrt/dht.go:450        key not found in map
Nov 18 16:01:36 kubo-staging-us-east-02 ipfs[573811]: 2024-11-18T16:01:36.963Z        ERROR        fullrtdht        fullrt/dht.go:450        key not found in map
Nov 18 16:01:36 kubo-staging-us-east-02 ipfs[573811]: 2024-11-18T16:01:36.963Z        ERROR        fullrtdht        fullrt/dht.go:450        key not found in map
Nov 18 16:01:36 kubo-staging-us-east-02 ipfs[573811]: 2024-11-18T16:01:36.966Z        ERROR        fullrtdht        fullrt/dht.go:450        key not found in map
Nov 18 16:01:36 kubo-staging-us-east-02 ipfs[573811]: 2024-11-18T16:01:36.966Z        ERROR        fullrtdht        fullrt/dht.go:450        key not found in map
Nov 18 16:01:36 kubo-staging-us-east-02 ipfs[573811]: 2024-11-18T16:01:36.966Z        ERROR        fullrtdht        fullrt/dht.go:450        key not found in map
Nov 18 16:01:37 kubo-staging-us-east-02 ipfs[573811]: 2024-11-18T16:01:37.077Z        ERROR        fullrtdht        fullrt/dht.go:450        key not found in map
Nov 18 16:01:37 kubo-staging-us-east-02 ipfs[573811]: 2024-11-18T16:01:37.086Z        ERROR        fullrtdht        fullrt/dht.go:450        key not found in map

Filling this issue so others can +1 if they also experienced it.
I'll monitor things for next few weeks and post update if we see it again in our infra.

Analysis

ERROR comes from:

func (dht *FullRT) GetClosestPeers(ctx context.Context, key string) ([]peer.ID, error) {
_, span := internal.StartSpan(ctx, "FullRT.GetClosestPeers", trace.WithAttributes(internal.KeyAsAttribute("Key", key)))
defer span.End()
kbID := kb.ConvertKey(key)
kadKey := kadkey.KbucketIDToKey(kbID)
dht.rtLk.RLock()
closestKeys := kademlia.ClosestN(kadKey, dht.rt, dht.bucketSize)
dht.rtLk.RUnlock()
peers := make([]peer.ID, 0, len(closestKeys))
for _, k := range closestKeys {
dht.kMapLk.RLock()
p, ok := dht.keyToPeerMap[string(k)]
if !ok {
logger.Errorf("key not found in map")
}
dht.kMapLk.RUnlock()
dht.peerAddrsLk.RLock()
peerAddrs := dht.peerAddrs[p]
dht.peerAddrsLk.RUnlock()
dht.h.Peerstore().AddAddrs(p, peerAddrs, peerstore.TempAddrTTL)
peers = append(peers, p)
}
return peers, nil
}

Two problems:

  • it seems this should not be error, but a debug log message
  • also, the fact we just log, and still process this non-existing peer, means the code will try to access peerAddrs for a non-existent peer, which could lead to unexpected behavior. It looks like a bug to me, or a very anti-pattern way of signaling there is no info for a peer.

Potential fix

Did not test it, but my intuition would be to log to debug + skip appending nil peer?

+ dht.kMapLk.RUnlock()
  if !ok {
-   logger.Errorf("key not found in map: %v", k)
+   logger.Debugf("key not found in map: %v", k)

+   continue
  }
- dht.kMapLk.RUnlock()

Metadata

Metadata

Assignees

Labels

P2Medium: Good to have, but can wait until someone steps upeffort/hoursEstimated to take one or several hoursexp/intermediatePrior experience is likely helpful

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions