{"record":{"id":"23f067e76f113559","repo":"gofiber/fiber","slug":"cache-failed-to-delete-key-q-w","errorCode":null,"errorMessage":"cache: failed to delete key %q: %w","messagePattern":"cache: failed to delete key %q: %w","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"middleware/cache/manager.go","lineNumber":201,"sourceCode":"\n// set data to storage or memory\nfunc (m *manager) setRaw(ctx context.Context, key string, raw []byte, exp time.Duration) error {\n\tif m.storage != nil {\n\t\tif err := m.storage.SetWithContext(ctx, key, raw, exp); err != nil {\n\t\t\treturn fmt.Errorf(\"cache: failed to store raw key %q: %w\", m.logKey(key), err)\n\t\t}\n\t\treturn nil\n\t}\n\n\tm.memory.Set(key, raw, exp)\n\treturn nil\n}\n\n// delete data from storage or memory\nfunc (m *manager) del(ctx context.Context, key string) error {\n\tif m.storage != nil {\n\t\tif err := m.storage.DeleteWithContext(ctx, key); err != nil {\n\t\t\treturn fmt.Errorf(\"cache: failed to delete key %q: %w\", m.logKey(key), err)\n\t\t}\n\t\treturn nil\n\t}\n\n\tm.memory.Delete(key)\n\treturn nil\n}\n\nfunc (m *manager) logKey(key string) string {\n\tif m.shouldRedactKeys {\n\t\treturn redactedKey\n\t}\n\treturn key\n}\n","sourceCodeStart":183,"sourceCodeEnd":216,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/middleware/cache/manager.go#L183-L216","documentation":"Returned by manager.del when the external Storage's DeleteWithContext fails. Deletion is invoked during cache invalidation/eviction and during cleanup paths; failure here leaves a stale or orphaned entry in the backend.","triggerScenarios":"Any path calling manager.del (cache invalidation, MaxBytes eviction cleanup, store-error cleanup) against a Storage backend whose DeleteWithContext errors: backend down, network error, permission/ACL denial on DEL, context cancellation.","commonSituations":"Redis ACL missing the DEL permission; backend transient outage during an eviction; client disconnect during invalidation; storage driver connection pool exhausted under churn.","solutions":["Check the wrapped error for permission (ACL) vs connectivity vs cancellation causes.","Ensure the configured Storage credentials have DEL permission.","Rely on TTL/expiration to eventually purge entries if explicit delete fails; do not fail the user request over a cleanup delete.","Verify connection pool health if deletes fail under load."],"exampleFix":"// before: surfacing delete failure from invalidation\nif err := manager.del(ctx, key); err != nil {\n    return err\n}\n\n// after: invalidation is best-effort; TTL is the safety net\nif err := manager.del(ctx, key); err != nil {\n    log.Warn(\"cache delete failed; entry will expire via TTL:\", err)\n}","handlingStrategy":"try-catch","validationCode":"func storageDeletable(ctx context.Context, s fiber.Storage) error {\n    if err := s.SetWithContext(ctx, \"__dprobe__\", []byte(\"x\"), time.Second); err != nil {\n        return err\n    }\n    return s.DeleteWithContext(ctx, \"__dprobe__\")\n}","typeGuard":null,"tryCatchPattern":"// Cache deletes are best-effort; TTL is the backstop.\nif err := manager.del(ctx, key); err != nil {\n    log.Warn(\"cache delete failed; entry will expire via TTL:\", err)\n}","preventionTips":["Grant the Storage credentials DEL permission.","Keep TTLs short enough that failed deletes self-heal.","Do not block request handling on cache invalidation."],"tags":["cache","storage","network","delete","eviction","go","fiber"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}