{"record":{"id":"cfb72494d2fdc022","repo":"ipfs/kubo","slug":"port-can-not-be-0","errorCode":null,"errorMessage":"port can not be 0","messagePattern":"port can not be 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/p2p.go","lineNumber":412,"sourceCode":"\t\tsport, _ = target.ValueForProtocol(ma.P_UDP)\n\t\tif sport != \"\" {\n\t\t\treturn sport, nil\n\t\t}\n\t\treturn \"\", errors.New(\"address does not contain tcp or udp protocol\")\n\t}\n\n\tsport, err := getPort()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tport, err := strconv.Atoi(sport)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif port == 0 {\n\t\treturn errors.New(\"port can not be 0\")\n\t}\n\n\treturn nil\n}\n\n// forwardLocal forwards local connections to a libp2p service\nfunc forwardLocal(ctx context.Context, p *p2p.P2P, ps pstore.Peerstore, proto protocol.ID, bindAddr ma.Multiaddr, addr *peer.AddrInfo) (p2p.Listener, error) {\n\tps.AddAddrs(addr.ID, addr.Addrs, pstore.TempAddrTTL)\n\treturn p.ForwardLocal(ctx, addr.ID, proto, bindAddr)\n}\n\nconst (\n\tp2pHeadersOptionName = \"headers\"\n)\n\nvar p2pLsCmd = &cmds.Command{\n\tStatus: cmds.Experimental,\n\tHelptext: cmds.HelpText{","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/p2p.go#L394-L430","documentation":"checkPort parses the port string extracted from a p2p multiaddr and rejects port 0. Port 0 is not a usable endpoint for a p2p forward/listen (it would mean an OS-assigned ephemeral port the peer cannot target), so the command errors out.","triggerScenarios":"Running an `ipfs p2p` command with a listen or target multiaddr containing `/tcp/0` or `/udp/0`, e.g. `ipfs p2p listen /p2p/x /ip4/127.0.0.1/tcp/0`.","commonSituations":"Copy-pasting placeholder configs with port 0; templating errors where a port variable was empty and defaulted to 0; confusing port 0 (auto-assign, valid for plain TCP servers) with what p2p tunneling allows.","solutions":["Specify an explicit nonzero port, e.g. `/ip4/127.0.0.1/tcp/8080`.","Fix templates/scripts so the port variable is never empty or 0 when the command runs.","Pick a free port explicitly (e.g. via a port-picking step in your tooling) rather than relying on OS auto-assignment."],"exampleFix":"// before\nipfs p2p forward /p2p/x/1.0.0 /ip4/127.0.0.1/tcp/0 <target>\n// after\nipfs p2p forward /p2p/x/1.0.0 /ip4/127.0.0.1/tcp/8080 <target>","handlingStrategy":"validation","validationCode":"sport, _ := m.ValueForProtocol(multiaddr.P_TCP)\nport, err := strconv.Atoi(sport)\nif err != nil || port <= 0 || port > 65535 {\n    return fmt.Errorf(\"invalid port %q\", sport)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reject port 0 in any config or template that feeds p2p commands.","Pick concrete free ports during deployment rather than relying on ephemeral assignment.","Range-check ports (1-65535) wherever multiaddrs are generated."],"tags":["p2p","validation","ports"],"backgroundTag":"invalid-port-zero","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"}