ipfs/kubo · error
error: can't ping self
Error message
error: can't ping self
What it means
`ErrPingSelf` is a sentinel error returned by the ping command when the target peer ID equals the local node's own identity (`n.Identity`). Pinging yourself is meaningless in the DHT/ping protocol, so kubo rejects it upfront. The doc comment explicitly marks it as the error for attempting to ping yourself.
Source
Thrown at core/commands/ping.go:33
pstore "github.com/libp2p/go-libp2p/core/peerstore"
ping "github.com/libp2p/go-libp2p/p2p/protocol/ping"
ma "github.com/multiformats/go-multiaddr"
)
const kPingTimeout = 10 * time.Second
type PingResult struct {
Success bool
Time time.Duration
Text string
}
const (
pingCountOptionName = "count"
)
// ErrPingSelf is returned when the user attempts to ping themself.
var ErrPingSelf = errors.New("error: can't ping self")
var PingCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Send echo request packets to IPFS hosts.",
ShortDescription: `
'ipfs ping' is a tool to test sending data to other nodes. It finds nodes
via the routing system, sends pings, waits for pongs, and prints out round-
trip latency information.
`,
},
Arguments: []cmds.Argument{
cmds.StringArg("peer ID", true, true, "ID of peer to be pinged.").EnableStdin(),
},
Options: []cmds.Option{
cmds.IntOption(pingCountOptionName, "n", "Number of ping messages to send.").WithDefault(10),
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
n, err := cmdenv.GetNode(env)View on GitHub (pinned to 329838acdf)
Solutions
- Ping a different peer: get a remote peer ID from `ipfs swarm peers` or `ipfs dht findprovidercmd` output and use that.
- Compare the target with `ipfs id --format='<id>'` before pinging and skip when equal (self-check in scripts).
- If you meant to test connectivity to yourself, use the daemon's own endpoints instead (e.g. `ipfs id`, API health) rather than `ipfs ping`.
- In code, check for `ErrPingSelf` with `errors.Is(err, corecommands.ErrPingSelf)` and treat it as a user mistake, not a network failure.
Example fix
// before (shell) SELF=$(ipfs id --format='<id>') ipfs ping "$SELF" // after SELF=$(ipfs id --format='<id>') TARGET="$argv[1]" [ "$TARGET" != "$SELF" ] && ipfs ping "$TARGET" || echo 'refusing to ping self'
Defensive patterns
Strategy: try-catch
Validate before calling
target, _ := peer.Decode(args[0])
self, _ := node.Identity.Decode()
if target == self {
return fmt.Errorf("refusing to ping self")
} Type guard
func isPingSelf(err error) bool {
return errors.Is(err, ErrPingSelf)
} Try / catch
pid, err := ipfsPing(ctx, target)
if err != nil {
if errors.Is(err, ErrPingSelf) {
// user mistake: skip or report, do not retry
return fmt.Errorf("target %s is the local node; pick a remote peer", target)
}
return err
} Prevention
- Filter the local node's own peer ID out of any peer list before pinging
- Resolve multiaddrs first and compare the decoded peer ID against `ipfs id`
- Treat ErrPingSelf as a usage error in tooling, distinct from network timeouts
- Never copy the peer ID from `ipfs id` when testing local connectivity
When it happens
Trigger: Running `ipfs ping <own-peer-id>` where the argument is the node's own ID from `ipfs id`; scripts that resolve a peer ID via DNSLink/multiaddr and accidentally resolve back to the local node; clusters/tests where a node list accidentally includes self.
Common situations: Copy-pasting the peer ID from `ipfs id` on the same machine you're testing from; loopback multiaddr pings (`ipfs ping /p2p/<self>`); automation iterating over a peer list that includes the local node without filtering.
Related errors
- invalid configuration profile: %s
- inline-limit %d exceeds maximum allowed size of %d bytes
- %s can't be used with UnixFS metadata like mode or modificat
- %s and %s options are not compatible
- %s option requires %s to be set
AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03).
Data as JSON: /api/errors/9625a1e8a4511432.
Report an issue: GitHub.