From 4841d6979ace3e6a4a468d9114d86e86dc00a8e3 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 21 Jul 2016 20:11:37 +0200 Subject: add maintenance task to get rid of dangeling user session objects diff --git a/rhimport/session_store.go b/rhimport/session_store.go index f25a297..a511d52 100644 --- a/rhimport/session_store.go +++ b/rhimport/session_store.go @@ -29,6 +29,7 @@ import ( "encoding/base64" "fmt" "net/http" + "time" "code.helsinki.at/rhrd-go/rddb" ) @@ -261,12 +262,26 @@ func (store *SessionStore) remove(username, id string) (resp removeSessionRespon return } +func (store *SessionStore) maintenanceTask() { + for name, user := range store.store { + user.callUpdateHandler(nil, nil) + if len(user.sessions) == 0 && len(user.updateCBs) == 0 { + delete(store.store, name) + rhdl.Printf("SessionStore: removed user '%s'", name) + } + } +} + func (store *SessionStore) dispatchRequests() { defer func() { store.done <- true }() + + mt := time.NewTicker(1 * time.Minute) for { select { case <-store.quit: return + case <-mt.C: + store.maintenanceTask() case req := <-store.newChan: req.response <- store.new(req.ctx, req.refId) case req := <-store.getChan: -- cgit v0.10.2