{"record":{"id":"1dd3c619230fd6bb","repo":"kataras/iris","slug":"session-not-found","errorCode":null,"errorMessage":"session not found","messagePattern":"session not found","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"sessions/provider.go","lineNumber":105,"sourceCode":"\tp.sessions[sid] = newSession\n\tp.mu.Unlock()\n\treturn newSession\n}\n\nfunc (p *provider) EndRequest(ctx *context.Context, session *Session) {\n\tif p.dbRequestHandler != nil {\n\t\tp.dbRequestHandler.EndRequest(ctx, session)\n\t}\n}\n\n// ErrNotFound may be returned from `UpdateExpiration` of a non-existing or\n// invalid session entry from memory storage or databases.\n// Usage:\n//\n//\tif err != nil && err.Is(err, sessions.ErrNotFound) {\n//\t    [handle error...]\n//\t}\nvar ErrNotFound = errors.New(\"session not found\")\n\n// UpdateExpiration resets the expiration of a session.\n// if expires > 0 then it will try to update the expiration and destroy task is delayed.\n// if expires <= 0 then it does nothing it returns nil, to destroy a session call the `Destroy` func instead.\n//\n// If the session is not found, it returns a `NotFound` error,  this can only happen when you restart the server and you used the memory-based storage(default),\n// because the call of the provider's `UpdateExpiration` is always called when the client has a valid session cookie.\n//\n// If a backend database is used then it may return an `ErrNotImplemented` error if the underline database does not support this operation.\nfunc (p *provider) UpdateExpiration(sid string, expires time.Duration) error {\n\tif expires <= 0 {\n\t\treturn nil\n\t}\n\n\tp.mu.RLock()\n\tsess, found := p.sessions[sid]\n\tp.mu.RUnlock()\n\tif !found {","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/sessions/provider.go#L87-L123","documentation":"sessions.ErrNotFound is the sentinel returned when a session ID cannot be resolved in memory storage or any registered databases — by Get, GetByID, Update, UpdateExpiration, Destroy and Delete flows. The docs recommend matching it with err.Is(err, sessions.ErrNotFound). It commonly happens after a server restart when using the default memory storage, since sessions are not persisted.","triggerScenarios":"Calling sess.Get(id) / GetByID(id) with an expired, destroyed, or never-created session ID; calling Update/UpdateExpiration/Delete on a session that was already destroyed or lost after a server restart with the in-memory provider.","commonSituations":"Server restarts while clients keep old session cookies (memory storage default); session expired due to inactivity; load-balanced deployments where another instance holds the session.","solutions":["Treat ErrNotFound as 'no session' and create a new session via sessions.Start / StartExpiring.","Persist sessions with a real database backend (badger, boltdb, redis) so they survive restarts.","Clear the stale cookie on the client when ErrNotFound is returned.","If clustering, use a shared session store so all instances see the same sessions."],"exampleFix":"// before\nsess := sessions.Get(ctx, sid) // nil or error on restart-lost id\n\n// after\nif err != nil && errors.Is(err, sessions.ErrNotFound) {\n    sess = sessions.Start(ctx) // new session\n}","handlingStrategy":"try-catch","validationCode":"// check cookie before hitting storage\nif sid := ctx.GetCookie(config.Cookie); sid == \"\" {\n    // no session yet — start a new one instead of Get(id)\n}","typeGuard":"func isSessionNotFound(err error) bool { return errors.Is(err, sessions.ErrNotFound) }","tryCatchPattern":"if err != nil && errors.Is(err, sessions.ErrNotFound) {\n    // lost/expired session: start a fresh one, clear stale cookie\n    sess = manager.Start(ctx)\n}","preventionTips":["Persist sessions in a durable backend if restarts occur.","Set sensible expiration and regenerate on login.","Handle ErrNotFound explicitly in session middleware."],"tags":["sessions","storage","not-found","iris"],"backgroundTag":"session-not-found","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}