{"id":"bacee5e40fe2abbc","repo":"gofiber/fiber","slug":"session-id-not-found-in-session-store","errorCode":null,"errorMessage":"session ID not found in session store","messagePattern":"session ID not found in session store","errorType":"exception","errorClass":"ErrSessionIDNotFoundInStore","httpStatus":null,"severity":"warning","filePath":"middleware/session/store.go","lineNumber":19,"sourceCode":"package session\n\nimport (\n\t\"context\"\n\t\"encoding/gob\"\n\t\"errors\"\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/gofiber/fiber/v3\"\n\t\"github.com/gofiber/fiber/v3/extractors\"\n\t\"github.com/gofiber/fiber/v3/internal/storage/memory\"\n\t\"github.com/gofiber/fiber/v3/log\"\n)\n\n// ErrEmptySessionID is an error that occurs when the session ID is empty.\nvar (\n\tErrEmptySessionID                   = errors.New(\"session ID cannot be empty\")\n\tErrSessionAlreadyLoadedByMiddleware = errors.New(\"session already loaded by middleware\")\n\tErrSessionIDNotFoundInStore         = errors.New(\"session ID not found in session store\")\n)\n\n// sessionIDKey is the local key type used to store and retrieve the session ID in context.\ntype sessionIDKey int\n\nconst (\n\t// sessionIDContextKey is the key used to store the session ID in the context locals.\n\tsessionIDContextKey sessionIDKey = iota\n\t// sessionExtractorContextKey stores the extractor that provided the session ID.\n\tsessionExtractorContextKey\n)\n\n// Store manages session data using the configured storage backend.\ntype Store struct {\n\tConfig\n}\n","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/middleware/session/store.go#L1-L37","documentation":"Declared as ErrSessionIDNotFoundInStore and returned by Store.GetByID when the storage backend returns nil data for the id (the id was never stored, was expired/evicted, or was destroyed). It is also returned when an AbsoluteTimeout has lapsed and GetByID destroys the expired session. It signals 'no such session', not a storage failure.","triggerScenarios":"store.GetByID(ctx, id) with an id from an old/expired cookie, a forged id, an id whose TTL elapsed, or an id whose session was destroyed by Reset/Destroy. Also returned when Config.AbsoluteTimeout fired and the session was auto-destroyed during lookup.","commonSituations":"Returning users after the session TTL expired; a client presenting a stale cookie after server restart with in-memory storage; cross-instance requests when storage isn't shared; explicit session destruction followed by reuse of the old id.","solutions":["Handle the error as 'session absent': create a fresh session / treat the user as unauthenticated.","If using AbsoluteTimeout, expect this near timeout boundaries and migrate to a fresh session id (Regenerate) before expiry.","Ensure the configured Storage is shared across all instances (Redis/external) so ids resolve consistently.","Increase session TTL or switch to a persistent backend if sessions expire too aggressively."],"exampleFix":"// before\nsess, err := store.GetByID(ctx, id)\nif err != nil { return err }\n\n// after\nsess, err := store.GetByID(ctx, id)\nif errors.Is(err, session.ErrSessionIDNotFoundInStore) {\n    // treat as anonymous / start fresh session\n    return c.Status(fiber.StatusUnauthorized).SendString(\"session expired\")\n}\nif err != nil { return err }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"sess, err := store.GetByID(ctx, id)\nif err != nil {\n    if errors.Is(err, session.ErrSessionIDNotFoundInStore) {\n        // expired/unknown/destroyed — start fresh / treat anonymous\n        return c.Status(fiber.StatusUnauthorized).SendString(\"session expired\")\n    }\n    return err\n}","preventionTips":["Expect this near AbsoluteTimeout boundaries and handle as a normal expiry.","Use a shared/persistent Storage (Redis) so ids resolve across all instances.","Regenerate session ids before absolute timeout to avoid mid-session expiry surprises."],"tags":["session","storage","not-found","expiry"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}