End a session unused for a day, and purge dead sessions and claims hourly
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
ba5158d463
commit
fd9f665ef8
4 files changed
+85
-6
No files matched your search
@@ -423,6 +423,38 @@ func (r *Router) Start(ctx context.Context) {
|
||||
}
|
||||
if r.store != nil {
|
||||
go r.refreshTenants(ctx)
|
||||
go r.purgeSessions(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
// purgeSessions deletes sessions and key claims that can no longer be used,
|
||||
// hourly and once at startup: refused already, but a table that only grows
|
||||
// is its own problem, and a session row is a credential's hash kept for
|
||||
// nothing.
|
||||
func (r *Router) purgeSessions(ctx context.Context) {
|
||||
purge := func() {
|
||||
now := time.Now()
|
||||
if n, err := r.store.PurgeSessions(ctx, now); err != nil {
|
||||
r.log.Warn("could not remove expired sessions", "err", err)
|
||||
} else if n > 0 {
|
||||
r.log.Info("removed expired and idle sessions", "sessions", n)
|
||||
}
|
||||
if n, err := r.store.PurgeClaims(ctx, now); err != nil {
|
||||
r.log.Warn("could not remove used and expired key claims", "err", err)
|
||||
} else if n > 0 {
|
||||
r.log.Info("removed used and expired key claims", "claims", n)
|
||||
}
|
||||
}
|
||||
purge()
|
||||
t := time.NewTicker(time.Hour)
|
||||
defer t.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-t.C:
|
||||
purge()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user