{"record":{"id":"b8fc5b46058c72c2","repo":"oauth2-proxy/oauth2-proxy","slug":"session-does-not-exist","errorCode":null,"errorMessage":"session does not exist","messagePattern":"session does not exist","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/sessions/redis/redis_store.go","lineNumber":53,"sourceCode":"\treturn persistence.NewManager(rs, cookieOpts), nil\n}\n\n// Save takes a sessions.SessionState and stores the information from it\n// to redis, and adds a new persistence cookie on the HTTP response writer\nfunc (store *SessionStore) Save(ctx context.Context, key string, value []byte, exp time.Duration) error {\n\terr := store.Client.Set(ctx, key, value, exp)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error saving redis session: %v\", err)\n\t}\n\treturn nil\n}\n\n// Load reads sessions.SessionState information from a persistence\n// cookie within the HTTP request object\nfunc (store *SessionStore) Load(ctx context.Context, key string) ([]byte, error) {\n\tvalue, err := store.Client.Get(ctx, key)\n\tif err == redis.Nil {\n\t\treturn nil, fmt.Errorf(\"session does not exist\")\n\t} else if err != nil {\n\t\treturn nil, fmt.Errorf(\"error loading redis session: %v\", err)\n\t}\n\n\treturn value, nil\n}\n\n// Clear clears any saved session information for a given persistence cookie\n// from redis, and then clears the session\nfunc (store *SessionStore) Clear(ctx context.Context, key string) error {\n\terr := store.Client.Del(ctx, key)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error clearing the session from redis: %v\", err)\n\t}\n\treturn nil\n}\n\n// Lock creates a lock object for sessions.SessionState","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/oauth2-proxy/oauth2-proxy/blob/33c2eb92dea78204f7a18bc2dfdbccc220f39257/pkg/sessions/redis/redis_store.go#L35-L71","documentation":"SessionStore.Load reads session bytes from Redis by key. When the Redis GET returns redis.Nil (the key simply does not exist), the store translates it into the sentinel error \"session does not exist\". It exists to distinguish a normal cache miss from a real Redis failure.","triggerScenarios":"Calling Load(ctx, key) with a key that was never Save()d, or whose entry expired (session TTL elapsed) or was flushed from Redis.","commonSituations":"User presents a stale persistence cookie after Redis restart/flushall or session expiry; Redis configured with short maxmemory eviction policies dropping session keys; clock/TTL mismatch causing early expiry.","solutions":["Treat this as an expected cache miss: re-authenticate the user and Save a fresh session instead of surfacing the error","Check Redis TTL config and session cookie lifetime so they align (cookie outliving the Redis entry causes this)","Verify the key format matches what Save used (prefix/version changes can orphan old cookies)","Confirm Redis still holds data: redis-cli GET the key manually; if empty after restart, sessions were not persisted"],"exampleFix":"// before\nstate, err := store.Load(ctx, cookieValue)\nif err != nil { return err }\n// after\nstate, err := store.Load(ctx, cookieValue)\nif err != nil {\n    if strings.Contains(err.Error(), \"session does not exist\") {\n        return startNewSession(ctx) // re-authenticate\n    }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"// Go: cannot pre-validate existence cheaply; check key non-empty\nif key == \"\" { return errors.New(\"empty session key\") }","typeGuard":"func isSessionNotExist(err error) bool { return err != nil && strings.Contains(err.Error(), \"session does not exist\") }","tryCatchPattern":"state, err := store.Load(ctx, key)\nif err != nil {\n    if isSessionNotExist(err) { return startNewSession(ctx) }\n    return fmt.Errorf(\"load session: %w\", err)\n}","preventionTips":["Align Redis session TTL with cookie max-age","Re-authenticate on miss instead of surfacing the error","Monitor miss rates; spikes indicate Redis restarts or eviction"],"tags":["redis","session","cache-miss"],"backgroundTag":"resource-not-found","analyzedSha":"33c2eb92dea78204f7a18bc2dfdbccc220f39257","analyzedAt":"2026-09-06T08:51:53.077Z","contentChangedAt":"2026-09-06T08:51:53.077Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}