{"record":{"id":"65ee719294e00b30","repo":"grpc/grpc-go","slug":"rls-cache-size-bytes-must-be-set-to-a-non-zero-va","errorCode":null,"errorMessage":"rls: cache_size_bytes must be set to a non-zero value: %+v","messagePattern":"rls: cache_size_bytes must be set to a non-zero value: %\\+v","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"balancer/rls/config.go","lineNumber":265,"sourceCode":"\n\tif staleAgeSet && !maxAgeSet {\n\t\treturn nil, fmt.Errorf(\"rls: stale_age is set, but max_age is not in route lookup config %+v\", rlsProto)\n\t}\n\tif staleAge > maxMaxAge {\n\t\tstaleAge = maxMaxAge\n\t}\n\tif !staleAgeSet && maxAge > maxMaxAge {\n\t\tmaxAge = maxMaxAge\n\t}\n\tif staleAge > maxAge {\n\t\tstaleAge = maxAge\n\t}\n\n\t// `cache_size_bytes` field must have a value greater than 0, and if its\n\t// value is greater than 5M, we cap it at 5M\n\tcacheSizeBytes := rlsProto.GetCacheSizeBytes()\n\tif cacheSizeBytes <= 0 {\n\t\treturn nil, fmt.Errorf(\"rls: cache_size_bytes must be set to a non-zero value: %+v\", rlsProto)\n\t}\n\tif cacheSizeBytes > maxCacheSize {\n\t\tlogger.Infof(\"rls: cache_size_bytes %v is too large, setting it to: %v\", cacheSizeBytes, maxCacheSize)\n\t\tcacheSizeBytes = maxCacheSize\n\t}\n\treturn &lbConfig{\n\t\tkbMap:                kbMap,\n\t\tlookupService:        lookupService,\n\t\tlookupServiceTimeout: lookupServiceTimeout,\n\t\tmaxAge:               maxAge,\n\t\tstaleAge:             staleAge,\n\t\tcacheSizeBytes:       cacheSizeBytes,\n\t\tdefaultTarget:        rlsProto.GetDefaultTarget(),\n\t}, nil\n}\n\n// parseChildPolicyConfigs iterates through the list of child policies and picks\n// the first registered policy and validates its config.","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/grpc/grpc-go/blob/0c51461d27177d997e14c642fe18c11668fc09a3/balancer/rls/config.go#L247-L283","documentation":"Emitted from parseRLSProto (config.go:265) when RouteLookupConfig.cache_size_bytes is <= 0. The RLS data cache must have a positive size; the client also caps it at maxCacheSize (5 MB). There is no default, so zero is an error.","triggerScenarios":"cache_size_bytes omitted (proto default 0) or set to a non-positive value in the RouteLookupConfig.","commonSituations":"Forgetting to set cache size in a hand-authored config; xDS RLS resource where the field was never populated; an operator setting it to 0 expecting 'unlimited'.","solutions":["Set cache_size_bytes to a positive value appropriate for your fan-out, e.g. 100000 (it will be capped at 5242880 if too large).","Populate the field in the control-plane RLS resource template with a sane non-zero default.","Treat cache size as required input during config validation in your deployment pipeline."],"exampleFix":"// before\n\"routeLookupConfig\": { \"cacheSizeBytes\": 0, ... }\n\n// after\n\"routeLookupConfig\": { \"cacheSizeBytes\": 100000, ... }","handlingStrategy":"validation","validationCode":"func validateCacheSize(b int64) error {\n    if b <= 0 {\n        return errors.New(\"cache_size_bytes must be greater than 0\")\n    }\n    return nil\n}","typeGuard":"func cacheSizeIsPositive(b int64) bool { return b > 0 }","tryCatchPattern":null,"preventionTips":["Always set cache_size_bytes; there is no default.","Pick a value relative to expected distinct keys (client caps at 5 MB).","Flag zero cache_size_bytes as a config-lint error."],"tags":["rls","cache","validation","service-config"],"backgroundTag":null,"analyzedSha":"0c51461d27177d997e14c642fe18c11668fc09a3","analyzedAt":"2026-08-11T14:49:15.055Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}