ipfs/kubo · error

GetClosestPeers key is undefined

Error message

GetClosestPeers key is undefined

What it means

The Routing RPC endpoint was called to find closest peers with cid.Undef as the key. Although the spec says an empty peer ID should default to self, this guard rejects an undefined CID key rather than guessing an intent for it.

Source

Thrown at core/corehttp/routing.go:107

func (r *contentRouter) PutIPNS(ctx context.Context, name ipns.Name, record *ipns.Record) error {
	ctx, cancel := context.WithCancel(ctx)
	defer cancel()

	raw, err := ipns.MarshalRecord(record)
	if err != nil {
		return err
	}

	// The caller guarantees that name matches the record. This is double checked
	// by the internals of PutValue.
	return r.n.Routing.PutValue(ctx, string(name.RoutingKey()), raw)
}

func (r *contentRouter) GetClosestPeers(ctx context.Context, key cid.Cid) (iter.ResultIter[*types.PeerRecord], error) {
	// Per the spec, if the peer ID is empty, we should use self.
	if key == cid.Undef {
		return nil, errors.New("GetClosestPeers key is undefined")
	}

	keyStr := string(key.Hash())
	var peers []peer.ID
	var err error

	if r.n.DHTClient == nil {
		return nil, fmt.Errorf("GetClosestPeers not supported: DHT is not available")
	}

	switch dhtClient := r.n.DHTClient.(type) {
	case *dual.DHT:
		// Only use WAN DHT for public HTTP Routing API.
		// LAN DHT contains private network peers that should not be exposed publicly.
		if dhtClient.WAN == nil {
			return nil, fmt.Errorf("GetClosestPeers not supported: WAN DHT is not available")
		}
		peers, err = dhtClient.WAN.GetClosestPeers(ctx, keyStr)

View on GitHub (pinned to 329838acdf)

Solutions

  1. Pass an actual CID to route the query to (e.g. from 'ipfs routing findprovs')
  2. If you wanted this node's closest peers, pass the node's own CID-derived key explicitly
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at core/corehttp/routing.go:107 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03). Data as JSON: /api/errors/4574f56dfb590077. Report an issue: GitHub.