diff options
author | Christian Pointner <equinox@helsinki.at> | 2016-07-21 18:11:37 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2016-07-21 18:11:37 (GMT) |
commit | 4841d6979ace3e6a4a468d9114d86e86dc00a8e3 (patch) | |
tree | 038deb8213821e75ddb05ec54ef82b142fd65946 | |
parent | aa31924e2c1b4f66bc975cf185e2868b74a1e89e (diff) |
add maintenance task to get rid of dangeling user session objects
-rw-r--r-- | rhimport/session_store.go | 15 |
1 files changed, 15 insertions, 0 deletions
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: |