{"record":{"id":"bbb218645cd49d32","repo":"thanos-io/thanos","slug":"failed-to-create-inmemory-cache","errorCode":null,"errorMessage":"failed to create inmemory cache","messagePattern":"failed to create inmemory cache","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/store/cache/caching_bucket_factory.go","lineNumber":121,"sourceCode":"\tcfg.CacheGetRange(\"chunks\", nil, isTSDBChunkFile, config.ChunkSubrangeSize, config.ChunkObjectAttrsTTL, config.ChunkSubrangeTTL, config.MaxChunksGetRangeRequests)\n\tcfg.CacheExists(\"meta.jsons\", nil, isMetaFile, config.MetafileExistsTTL, config.MetafileDoesntExistTTL)\n\tcfg.CacheGet(\"meta.jsons\", nil, isMetaFile, int(config.MetafileMaxSize), config.MetafileContentTTL, config.MetafileExistsTTL, config.MetafileDoesntExistTTL)\n\n\t// Cache Iter requests for root.\n\tcfg.CacheIter(\"blocks-iter\", nil, isBlocksRootDir, config.BlocksIterTTL, JSONIterCodec{}, cfgHash)\n\n\tswitch strings.ToUpper(string(config.Type)) {\n\tcase string(MemcachedBucketCacheProvider):\n\t\tvar memcached cacheutil.RemoteCacheClient\n\t\tmemcached, err := cacheutil.NewMemcachedClient(logger, \"caching-bucket\", backendConfig, reg)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrapf(err, \"failed to create memcached client\")\n\t\t}\n\t\tc = cache.NewMemcachedCache(\"caching-bucket\", logger, memcached, reg)\n\tcase string(InMemoryBucketCacheProvider):\n\t\tc, err = cache.NewInMemoryCache(\"caching-bucket\", logger, reg, backendConfig)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrapf(err, \"failed to create inmemory cache\")\n\t\t}\n\tcase string(GroupcacheBucketCacheProvider):\n\t\tconst basePath = \"/_galaxycache/\"\n\n\t\tc, err = cache.NewGroupcache(logger, reg, backendConfig, basePath, r, bucket, cfg)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"failed to create groupcache\")\n\t\t}\n\n\tcase string(RedisBucketCacheProvider):\n\t\tredisCache, err := cacheutil.NewRedisClient(logger, \"caching-bucket\", backendConfig, reg)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrapf(err, \"failed to create redis client\")\n\t\t}\n\t\tc = cache.NewRedisCache(\"caching-bucket\", logger, redisCache, reg)\n\tdefault:\n\t\treturn nil, errors.Errorf(\"unsupported cache type: %s\", config.Type)\n\t}","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/store/cache/caching_bucket_factory.go#L103-L139","documentation":"When the cache type is IN-MEMORY, the factory builds an in-process cache via cache.NewInMemoryCache; any construction error is wrapped as 'failed to create inmemory cache'. The in-memory cache constructor validates its own config (max sizes, item limits).","triggerScenarios":"CachingWithBackendConfig.Type == IN-MEMORY and NewInMemoryCache returns an error, typically due to invalid InMemoryCacheConfig values such as negative max_size or max_size_items, or an unmarshal failure of the backendConfig into the in-memory config.","commonSituations":"Setting max_size to a negative or unparseable size in the caching YAML, putting memcached-specific keys under an IN-MEMORY cache entry, or running a Thanos version where in-memory cache config options changed.","solutions":["Check that max_size and max_size_items are non-negative and correctly formatted (e.g. 536870912 or 512MB)","Remove backend-specific keys that do not belong to the IN-MEMORY provider","Read the wrapped inner error for the exact invalid field","Validate config against the docs at Thanos caching_bucket.md for your version","Default the values (omit them) to let the library apply defaults"],"exampleFix":"// before\nconfig:\n  caches:\n    chunks:\n      max_size: -1\n// after\nconfig:\n  caches:\n    chunks:\n      max_size: 512MB\n      max_size_items: 0","handlingStrategy":"validation","validationCode":"if maxSize < 0 || maxSizeItems < 0 { return errors.New(\"in-memory cache sizes must be non-negative\") }","typeGuard":null,"tryCatchPattern":"cb, err := storecache.NewCachingBucketFromYaml(yamlContent, logger, reg, bucket, router)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to create inmemory cache\") {\n        return fmt.Errorf(\"in-memory cache config invalid (check max_size/max_size_items): %w\", err)\n    }\n    return err\n}","preventionTips":["Keep max_size and max_size_items non-negative","Omit fields to use library defaults","Do not mix memcached/redis keys under IN-MEMORY entries"],"tags":["go","cache","config","thanos"],"backgroundTag":"invalid-config-value","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}