{"record":{"id":"5f436d2117b82629","repo":"ipfs/kubo","slug":"dht-client-does-not-support-getclosestpeers","errorCode":null,"errorMessage":"dht client does not support GetClosestPeers","messagePattern":"dht client does not support GetClosestPeers","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/dht.go","lineNumber":81,"sourceCode":"\t\tid, err := peer.Decode(req.Arguments[0])\n\t\tif err != nil {\n\t\t\treturn cmds.ClientError(\"invalid peer ID\")\n\t\t}\n\n\t\tctx, cancel := context.WithCancel(req.Context)\n\t\tdefer cancel()\n\t\tctx, events := routing.RegisterForQueryEvents(ctx)\n\n\t\tclient := nd.DHTClient\n\t\tif nd.DHT != nil && client == nd.DHT {\n\t\t\tclient = nd.DHT.WAN\n\t\t\tif !nd.DHT.WANActive() {\n\t\t\t\tclient = nd.DHT.LAN\n\t\t\t}\n\t\t}\n\n\t\tif d, ok := client.(kademlia); !ok {\n\t\t\treturn errors.New(\"dht client does not support GetClosestPeers\")\n\t\t} else {\n\t\t\terrCh := make(chan error, 1)\n\t\t\tgo func() {\n\t\t\t\tdefer close(errCh)\n\t\t\t\tdefer cancel()\n\t\t\t\tclosestPeers, err := d.GetClosestPeers(ctx, string(id))\n\t\t\t\tfor _, p := range closestPeers {\n\t\t\t\t\trouting.PublishQueryEvent(ctx, &routing.QueryEvent{\n\t\t\t\t\t\tID:   p,\n\t\t\t\t\t\tType: routing.FinalPeer,\n\t\t\t\t\t})\n\t\t\t\t}\n\n\t\t\t\tif err != nil {\n\t\t\t\t\terrCh <- err\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}()","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/dht.go#L63-L99","documentation":"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.","triggerScenarios":"`ipfs dht query <peerID>` where the resolved client routing (nd.DHT.LAN or WAN) is a non-kademlia implementation that lacks GetClosestPeers.","commonSituations":"Custom or delegated routing implementations injected via config or plugins; hybrid LAN/WAN DHT setups where one side is not a kad-DHT.","solutions":["Ensure Routing.Type uses the standard kad-DHT (auto/dhtclient/dhtserver)","Use `ipfs routing` commands that work with any router instead of `ipfs dht query`","If running custom routing, implement GetClosestPeers or wrap the standard kademlia DHT"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"cctx := env.(*oldcmds.Context)\nclient := cctx.DHT // resolve LAN/WAN as the command does\nif client == nil { return ErrNotDHT }","typeGuard":"d, ok := client.(kademlia)\nif !ok { return errors.New(\"dht client does not support GetClosestPeers\") }","tryCatchPattern":"err := dhtQuery(ctx, peerID)\nif err != nil && strings.Contains(err.Error(), \"does not support GetClosestPeers\") { /* switch to routing-agnostic API */ }","preventionTips":["Use the iface.Routing API surface instead of asserting concrete kademlia types","Ensure standard kad-DHT routing is configured when kad-specific ops are needed"],"tags":["routing","dht","cli","type-assertion"],"backgroundTag":"routing-not-dht","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}