ipfs/kubo · error

dht client does not support GetClosestPeers

Error message

dht client does not support GetClosestPeers

What it means

Raised by `ipfs dht query` when the node's active DHT client does not implement the local `kademlia` interface (which requires GetClosestPeers). The command type-asserts the routing client to kademlia; if the assertion fails the routing service cannot serve closest-peer queries. Equivalent in spirit to ErrNotDHT but at the interface level.

Source

Thrown at core/commands/dht.go:81

		id, err := peer.Decode(req.Arguments[0])
		if err != nil {
			return cmds.ClientError("invalid peer ID")
		}

		ctx, cancel := context.WithCancel(req.Context)
		defer cancel()
		ctx, events := routing.RegisterForQueryEvents(ctx)

		client := nd.DHTClient
		if nd.DHT != nil && client == nd.DHT {
			client = nd.DHT.WAN
			if !nd.DHT.WANActive() {
				client = nd.DHT.LAN
			}
		}

		if d, ok := client.(kademlia); !ok {
			return errors.New("dht client does not support GetClosestPeers")
		} else {
			errCh := make(chan error, 1)
			go func() {
				defer close(errCh)
				defer cancel()
				closestPeers, err := d.GetClosestPeers(ctx, string(id))
				for _, p := range closestPeers {
					routing.PublishQueryEvent(ctx, &routing.QueryEvent{
						ID:   p,
						Type: routing.FinalPeer,
					})
				}

				if err != nil {
					errCh <- err
					return
				}
			}()

View on GitHub (pinned to 329838acdf)

Solutions

  1. Ensure Routing.Type uses the standard kad-DHT (auto/dhtclient/dhtserver)
  2. Use `ipfs routing` commands that work with any router instead of `ipfs dht query`
  3. If running custom routing, implement GetClosestPeers or wrap the standard kademlia DHT
Defensive patterns

Strategy: type-guard

Validate before calling

cctx := env.(*oldcmds.Context)
client := cctx.DHT // resolve LAN/WAN as the command does
if client == nil { return ErrNotDHT }

Type guard

d, ok := client.(kademlia)
if !ok { return errors.New("dht client does not support GetClosestPeers") }

Try / catch

err := dhtQuery(ctx, peerID)
if err != nil && strings.Contains(err.Error(), "does not support GetClosestPeers") { /* switch to routing-agnostic API */ }

Prevention

When it happens

Trigger: `ipfs dht query <peerID>` where the resolved client routing (nd.DHT.LAN or WAN) is a non-kademlia implementation that lacks GetClosestPeers.

Common situations: Custom or delegated routing implementations injected via config or plugins; hybrid LAN/WAN DHT setups where one side is not a kad-DHT.

Related errors


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