From 18257f03026900c003ce60edab4bdae450d7c28d Mon Sep 17 00:00:00 2001 From: James Houlahan Date: Fri, 17 Sep 2021 11:30:43 +0200 Subject: [PATCH] GODT-1350: stop cacher/worker properly when logging out user --- internal/store/store.go | 18 ++++++++---------- internal/users/user.go | 6 +++--- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/internal/store/store.go b/internal/store/store.go index 03de5d0f..9c553af7 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -413,22 +413,20 @@ func (store *Store) Close() error { return store.close() } -// CloseEventLoop stops the eventloop (if it is present). -func (store *Store) CloseEventLoop() { +// CloseEventLoopAndCacher stops the eventloop (if it is present). +func (store *Store) CloseEventLoopAndCacher() { if store.eventLoop != nil { store.eventLoop.stop() } + + store.stopWatcher() + + store.cacher.stop() } func (store *Store) close() error { - // Stop the watcher first before closing the database. - store.stopWatcher() - - // Stop the cacher. - store.cacher.stop() - - // Stop the event loop. - store.CloseEventLoop() + // Stop the event loop and cacher first before closing the DB. + store.CloseEventLoopAndCacher() // Close the database. return store.db.Close() diff --git a/internal/users/user.go b/internal/users/user.go index 5f9ef246..b6bcf3d4 100644 --- a/internal/users/user.go +++ b/internal/users/user.go @@ -450,7 +450,7 @@ func (u *User) Logout() error { } // Do not close whole store, just event loop. Some information might be needed offline (e.g. addressID) - u.closeEventLoop() + u.closeEventLoopAndCacher() u.CloseAllConnections() @@ -459,12 +459,12 @@ func (u *User) Logout() error { return nil } -func (u *User) closeEventLoop() { +func (u *User) closeEventLoopAndCacher() { if u.store == nil { return } - u.store.CloseEventLoop() + u.store.CloseEventLoopAndCacher() } // CloseAllConnections calls CloseConnection for all users addresses.