{"record":{"id":"348b65b425349ee0","repo":"ipfs/kubo","slug":"not-connected","errorCode":null,"errorMessage":"not connected","messagePattern":"not connected","errorType":"exception","errorClass":"ErrNotConnected","httpStatus":null,"severity":"warning","filePath":"core/coreiface/swarm.go","lineNumber":16,"sourceCode":"package iface\n\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"time\"\n\n\t\"github.com/libp2p/go-libp2p/core/network\"\n\t\"github.com/libp2p/go-libp2p/core/peer\"\n\t\"github.com/libp2p/go-libp2p/core/protocol\"\n\n\tma \"github.com/multiformats/go-multiaddr\"\n)\n\nvar (\n\tErrNotConnected = errors.New(\"not connected\")\n\tErrConnNotFound = errors.New(\"conn not found\")\n)\n\n// ConnectionInfo contains information about a peer\ntype ConnectionInfo interface {\n\t// ID returns PeerID\n\tID() peer.ID\n\n\t// Address returns the multiaddress via which we are connected with the peer\n\tAddress() ma.Multiaddr\n\n\t// Direction returns which way the connection was established\n\tDirection() network.Direction\n\n\t// Latency returns last known round trip time to the peer\n\tLatency() (time.Duration, error)\n\n\t// Streams returns list of streams established with the peer","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/coreiface/swarm.go#L1-L34","documentation":"ErrNotConnected is the sentinel error of the CoreAPI swarm interface, defined in core/coreiface/swarm.go. Swarm Disconnect returns it when you ask to disconnect from a peer that has no active connection — the node checks the libp2p host's Connectedness and short-circuits with this error if the peer is not in the Connected state.","triggerScenarios":"Calling api.Swarm().Disconnect(ctx, peerID) (peer-ID form, core/coreapi/swarm.go:75) for a peer whose conn.Connectedness(id) != inet.Connected — the peer was never connected, already dropped the connection, or a peer ID is passed while the node is offline. Also returned by Disconnect generally when no matching live connection exists.","commonSituations":"Disconnecting in cleanup/shutdown code after the connection already timed out or was closed elsewhere; races where the remote peer disconnects between your check and call; typos in the peer ID so it never matched a real peer; calling before the daemon finished bootstrapping.","solutions":["Treat errors.Is(err, coreiface.ErrNotConnected) as success in disconnect/cleanup code — the desired end state (no connection) already holds","Call api.Swarm().Peers(ctx) first to confirm the peer ID is present before disconnecting","Verify the peer ID is correct (peer.Decode) and that the node is running and dialed the peer (Swarm().Connect) if a live connection was expected"],"exampleFix":"// before\nerr := api.Swarm().Disconnect(ctx, peerID)\nif err != nil {\n    return err // fails during cleanup when peer already gone\n}\n\n// after\nerr := api.Swarm().Disconnect(ctx, peerID)\nif err != nil && !errors.Is(err, coreiface.ErrNotConnected) {\n    return err\n}","handlingStrategy":"try-catch","validationCode":"peers, err := api.Swarm().Peers(ctx)\nif err != nil {\n    return err\n}\nconnected := false\nfor _, p := range peers {\n    if p.ID() == targetID {\n        connected = true\n        break\n    }\n}\nif connected {\n    if err := api.Swarm().Disconnect(ctx, targetID); err != nil && !errors.Is(err, coreiface.ErrNotConnected) {\n        return err\n    }\n}","typeGuard":"func isNotConnectedErr(err error) bool {\n    return errors.Is(err, coreiface.ErrNotConnected)\n}","tryCatchPattern":"err := api.Swarm().Disconnect(ctx, peerID)\nswitch {\ncase err == nil:\n    // disconnected\ncase errors.Is(err, coreiface.ErrNotConnected):\n    // already disconnected: treat as success in cleanup paths\ndefault:\n    return fmt.Errorf(\"disconnect %s: %w\", peerID, err)\n}","preventionTips":["Idempotent-disconnect habit: always tolerate ErrNotConnected in teardown code","Confirm connectivity with Swarm().Peers before a Disconnect you expect to succeed","Re-check peer IDs with peer.Decode before calling — a malformed ID never matches a peer","Remember connections can drop asynchronously; the error may reflect a race, not a bug"],"tags":["swarm","libp2p","network","disconnect"],"backgroundTag":"peer-not-connected","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"}