{"record":{"id":"da6f1ad69952776b","repo":"ipfs/kubo","slug":"bug-unhandled-autonat-service-mode","errorCode":null,"errorMessage":"BUG: unhandled autonat service mode","messagePattern":"BUG: unhandled autonat service mode","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/node/groups.go","lineNumber":99,"sourceCode":"\t\tpubsubOptions = append(pubsubOptions, pubsub.WithSeenMessagesStrategy(seenMessagesStrategy))\n\n\t\tswitch cfg.Pubsub.Router {\n\t\tcase \"\":\n\t\t\tfallthrough\n\t\tcase \"gossipsub\":\n\t\t\tps = fx.Provide(libp2p.GossipSub(pubsubOptions...))\n\t\tcase \"floodsub\":\n\t\t\tps = fx.Provide(libp2p.FloodSub(pubsubOptions...))\n\t\tdefault:\n\t\t\treturn fx.Error(fmt.Errorf(\"unknown pubsub router %s\", cfg.Pubsub.Router))\n\t\t}\n\t}\n\n\tautonat := fx.Options()\n\n\tswitch cfg.AutoNAT.ServiceMode {\n\tdefault:\n\t\tpanic(\"BUG: unhandled autonat service mode\")\n\tcase config.AutoNATServiceDisabled:\n\tcase config.AutoNATServiceUnset:\n\t\t// TODO\n\t\t//\n\t\t// We're enabling the AutoNAT service by default on _all_ nodes\n\t\t// for the moment.\n\t\t//\n\t\t// We should consider disabling it by default if the dht is set\n\t\t// to dhtclient.\n\t\tfallthrough\n\tcase config.AutoNATServiceEnabled:\n\t\tautonat = fx.Provide(libp2p.AutoNATService(cfg.AutoNAT.Throttle, false))\n\tcase config.AutoNATServiceEnabledV1Only:\n\t\tautonat = fx.Provide(libp2p.AutoNATService(cfg.AutoNAT.Throttle, true))\n\t}\n\n\tenableTCPTransport := cfg.Swarm.Transports.Network.TCP.WithDefault(true)\n\tenableWebsocketTransport := cfg.Swarm.Transports.Network.Websocket.WithDefault(true)","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/node/groups.go#L81-L117","documentation":"AutoNAT.ServiceMode is validated against known values (Disabled, Unset, Enabled) when building the libp2p node; the switch intentionally panics for anything else because config validation should have rejected unknown values earlier. Reaching this panic indicates a genuine code/config-layer bug, not user error.","triggerScenarios":"`cfg.AutoNAT.ServiceMode` holds a value that passed earlier parsing but is not one of the enumerated cases — a bug in config deserialization or a new enum value added without updating this switch.","commonSituations":"A dev build or patched Kubo where a new AutoNATService constant was added but the LibP2P switch in core/node/groups.go was not updated; corrupted config producing an unexpected intermediate value.","solutions":["Report a bug at https://github.com/ipfs/kubo/issues with the config's AutoNAT.ServiceMode value and Kubo version","Inspect `ipfs config AutoNAT.ServiceMode` and set it to \"enabled\" or \"disabled\" to work around the panic","Update/rollback to a released Kubo version where the switch covers the config value"],"exampleFix":"// before (groups.go)\nswitch cfg.AutoNAT.ServiceMode {\ndefault:\n\tpanic(\"BUG: unhandled autonat service mode\")\ncase config.AutoNATServiceDisabled:\n// after (add the missing case)\nswitch cfg.AutoNAT.ServiceMode {\ndefault:\n\tpanic(\"BUG: unhandled autonat service mode\")\ncase config.AutoNATServiceDisabled:\ncase config.AutoNATServiceNewMode: // newly added enum value\n\t// handle new mode\n","handlingStrategy":"validation","validationCode":"// Ensure AutoNAT.ServiceMode is a known value before constructing the node\nswitch cfg.AutoNAT.ServiceMode {\ncase \"\", \"disabled\", \"enabled\", \"enable\" /* per version constants */:\n\t// ok\ndefault:\n\treturn fmt.Errorf(\"AutoNAT.ServiceMode %q unknown\", cfg.AutoNAT.ServiceMode)\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n\tif r := recover(); r != nil {\n\t\tlog.Errorf(\"node construction panicked: %v\", r)\n\t}\n}()","preventionTips":["Keep config package enum constants and the LibP2P switch in sync when adding modes","Set AutoNAT.ServiceMode only via documented CLI values","Report panics with the exact config value and Kubo version"],"tags":["autonat","bug","panic","libp2p"],"backgroundTag":"unhandled-switch-case","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"}