{"record":{"id":"f9052f514df47827","repo":"SigNoz/signoz","slug":"codeinternal-f9052f","errorCode":"CodeInternal","errorMessage":"error writing to cache","messagePattern":"error writing to cache","errorType":"error_code","errorClass":"errors.SignozError","httpStatus":500,"severity":"warning","filePath":"pkg/cache/memorycache/provider.go","lineNumber":124,"sourceCode":"\tif err != nil {\n\t\treturn err\n\t}\n\n\t// To make sure ristretto does not go into no-op\n\tif ttl < 0 {\n\t\tprovider.settings.Logger().WarnContext(ctx, \"ttl is less than 0, setting it to 0\")\n\t\tttl = 0\n\t}\n\n\tif cloneable, ok := data.(cachetypes.Cloneable); ok {\n\t\tcost := max(cloneable.Cost(), 1)\n\t\t// Clamp to a minimum of 1: ristretto treats cost 0 specially and we\n\t\t// never want zero-size entries to bypass admission accounting.\n\t\tspan.SetAttributes(attribute.Bool(\"memory.cloneable\", true))\n\t\tspan.SetAttributes(attribute.Int64(\"memory.cost\", cost))\n\t\ttoCache := cloneable.Clone()\n\t\tif ok := provider.cc.SetWithTTL(strings.Join([]string{orgID.StringValue(), cacheKey}, \"::\"), toCache, cost, ttl); !ok {\n\t\t\treturn errors.New(errors.TypeInternal, errors.CodeInternal, \"error writing to cache\")\n\t\t}\n\n\t\tprovider.cc.Wait()\n\t\treturn nil\n\t}\n\n\ttoCache, err := provider.marshalBinary(ctx, data)\n\tif err != nil {\n\t\treturn err\n\t}\n\tcost := max(int64(len(toCache)), 1)\n\n\tspan.SetAttributes(attribute.Bool(\"memory.cloneable\", false))\n\tspan.SetAttributes(attribute.Int64(\"memory.cost\", cost))\n\n\tif ok := provider.cc.SetWithTTL(strings.Join([]string{orgID.StringValue(), cacheKey}, \"::\"), toCache, cost, ttl); !ok {\n\t\treturn errors.New(errors.TypeInternal, errors.CodeInternal, \"error writing to cache\")\n\t}","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/cache/memorycache/provider.go#L106-L142","documentation":"Returned by the in-memory (ristretto) cache Set when SetWithTTL returns false, meaning ristretto declined to admit the entry (its admission policy rejected it, or the cache was closed). The library surfaces this as an internal error rather than silently dropping the entry.","triggerScenarios":"Calling Set on a Cloneable cacheable value whose entry ristretto rejects — cost exceeds capacity, the item is frequently rejected by the admission policy, or the cache was shut down mid-write.","commonSituations":"Cache capacity configured too small for large span/trace objects; many concurrent sets with tiny TTLs; calling Set after cache Close in tests or during shutdown; KeepUntil/eviction pressure.","solutions":["Increase the memory cache capacity/numCounters tuning so ristretto admits your entries","Cache smaller objects, or check entry sizes vs configured max cost","Avoid Set calls after Close; guard lifecycle in shutdown paths","If dropping entries is acceptable, treat this error as non-fatal and log-and-continue"],"exampleFix":"// after: tolerate admission rejection (log instead of fail)\nif err := cache.Set(ctx, orgID, key, val, ttl); err != nil {\n    if err.Error() == \"error writing to cache\" {\n        log.Warn(\"cache admission rejected\", \"key\", key)\n    } else { return err }\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":"func isCacheAdmissionErr(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"error writing to cache\")\n}","tryCatchPattern":"if err := cache.Set(ctx, orgID, key, v, ttl); err != nil {\n    if isCacheAdmissionErr(err) {\n        log.Warn(\"cache admission rejected; continuing without caching\", \"key\", key)\n    } else {\n        return err\n    }\n}","preventionTips":["Size the memory cache for your largest entries; treat cache as best-effort in read paths","Don't call Set after Close; wire cache lifecycle into service shutdown"],"tags":["cache","ristretto","memory","go"],"backgroundTag":"cache-write-rejected","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}