From 47ac505cac7b481192bbd78b9f33b4ce1bc1f66a Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Tue, 6 Apr 2021 18:12:06 +0100 Subject: [PATCH] shutdown your background workers! I believe everything #74 was caused by not shutting down the userDaemon when we do a pseudo-restart. shutdown of it and the invite daemon are now deferred so this should fix any problems and reduce log spam. --- main.go | 6 ++++-- userdaemon.go | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index db9b1d3..8d33fae 100644 --- a/main.go +++ b/main.go @@ -576,11 +576,13 @@ func start(asDaemon, firstCall bool) { os.Exit(0) } - inviteDaemon := newInviteDaemon(time.Duration(60*time.Second), app) - go inviteDaemon.run() + invDaemon := newInviteDaemon(time.Duration(60*time.Second), app) + go invDaemon.run() + defer invDaemon.shutdown() userDaemon := newUserDaemon(time.Duration(60*time.Second), app) go userDaemon.run() + defer userDaemon.shutdown() if app.config.Section("password_resets").Key("enabled").MustBool(false) && serverType == mediabrowser.JellyfinServer { go app.StartPWR() diff --git a/userdaemon.go b/userdaemon.go index 2df7fc9..c2c549b 100644 --- a/userdaemon.go +++ b/userdaemon.go @@ -42,6 +42,13 @@ func (rt *userDaemon) run() { } } +func (rt *userDaemon) shutdown() { + rt.Stopped = true + rt.ShutdownChannel <- "Down" + <-rt.ShutdownChannel + close(rt.ShutdownChannel) +} + func (app *appContext) checkUsers() { if err := app.storage.loadUsers(); err != nil { app.err.Printf("Failed to load user expiries: %v", err)