{"record":{"id":"785f1e7eedbec69c","repo":"ipfs/kubo","slug":"cannot-specify-negative-resolve-cache-size-785f1e","errorCode":null,"errorMessage":"cannot specify negative resolve cache size","messagePattern":"cannot specify negative resolve cache size","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/corehttp/gateway.go","lineNumber":168,"sourceCode":"\tcfg, err := n.Repo.Config()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tbserv := n.Blocks\n\tvar vsRouting routing.ValueStore = n.Routing\n\tnsys := n.Namesys\n\tpathResolver := n.UnixFSPathResolver\n\n\tif cfg.Gateway.NoFetch {\n\t\tbserv = blockservice.New(bserv.Blockstore(), offline.Exchange(bserv.Blockstore()))\n\n\t\tcs := cfg.Ipns.ResolveCacheSize\n\t\tif cs == 0 {\n\t\t\tcs = node.DefaultIpnsCacheSize\n\t\t}\n\t\tif cs < 0 {\n\t\t\treturn nil, fmt.Errorf(\"cannot specify negative resolve cache size\")\n\t\t}\n\n\t\tnsOptions := []namesys.Option{\n\t\t\tnamesys.WithDatastore(n.Repo.Datastore()),\n\t\t\tnamesys.WithDNSResolver(n.DNSResolver),\n\t\t\tnamesys.WithCache(cs),\n\t\t\tnamesys.WithMaxCacheTTL(cfg.Ipns.MaxCacheTTL.WithDefault(config.DefaultIpnsMaxCacheTTL)),\n\t\t}\n\n\t\tvsRouting = offlineroute.NewOfflineRouter(irouting.DHTValueDatastore(n.Repo.Datastore()), n.RecordValidator)\n\t\tnsys, err = namesys.NewNameSystem(vsRouting, nsOptions...)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error constructing namesys: %w\", err)\n\t\t}\n\n\t\t// Gateway.NoFetch=true requires offline path resolver\n\t\t// to avoid fetching missing blocks during path traversal\n\t\tpathResolver = n.OfflineUnixFSPathResolver","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/corehttp/gateway.go#L150-L186","documentation":"When building the gateway backend, kubo reads the `Ipns.ResolveCacheSize` config value to size the IPNS resolution cache; 0 means 'use the default'. A negative value is meaningless for a cache size, so newGatewayBackend rejects it with this error before the gateway can start.","triggerScenarios":"Setting `ipfs config --json Ipns.ResolveCacheSize -1` (or any negative number) and then starting the daemon, which fails during gateway construction.","commonSituations":"Hand-edited config files with a typo'd minus sign; copy-pasted tuning snippets intended for a different option; operators trying to 'disable' the cache by using a negative size instead of a valid value.","solutions":["Set the value to a non-negative integer: `ipfs config --json Ipns.ResolveCacheSize 128` (entries), or 0 to use kubo's default (node.DefaultIpnsCacheSize).","Validate the config before starting: `ipfs config --json Ipns.ResolveCacheSize` and confirm it is >= 0.","If the goal is to disable caching, use the supported knob `Ipns.MaxCacheTTL` (e.g. a tiny TTL) instead of a negative cache size.","Restore a known-good config: `ipfs config --json Ipns.ResolveCacheSize 0`."],"exampleFix":"// before (invalid config)\nipfs config --json Ipns.ResolveCacheSize -1\n\n// after\nipfs config --json Ipns.ResolveCacheSize 0   // 0 = default cache size","handlingStrategy":"validation","validationCode":"cs, err := repo.Config().Ipns.ResolveCacheSize // int\nif err != nil {\n    return err\n}\nif cs < 0 {\n    return fmt.Errorf(\"Ipns.ResolveCacheSize must be >= 0, got %d\", cs)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat config edits as code: keep Ipns.ResolveCacheSize in version control or infrastructure-as-code with a >= 0 check.","Use 0 (default) instead of hand-picking sizes unless you measured a need.","Run `ipfs config --json Ipns.ResolveCacheSize` in deploy scripts before starting the daemon.","Remember negative values are never valid for cache sizes; to reduce caching use Ipns.MaxCacheTTL instead."],"tags":["config","gateway","ipns","validation"],"backgroundTag":"invalid-config-value","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"}