diff --git a/plugin/environment.go b/plugin/environment.go index d301a8942e..a6345579d6 100644 --- a/plugin/environment.go +++ b/plugin/environment.go @@ -284,6 +284,10 @@ func (env *Environment) RestartPlugin(id string) error { // Shutdown deactivates all plugins and gracefully shuts down the environment. func (env *Environment) Shutdown() { + if env.pluginHealthCheckJob != nil { + env.pluginHealthCheckJob.Cancel() + } + env.registeredPlugins.Range(func(key, value interface{}) bool { rp := value.(*registeredPlugin) diff --git a/plugin/health_check.go b/plugin/health_check.go index 7f9855e125..85989e4775 100644 --- a/plugin/health_check.go +++ b/plugin/health_check.go @@ -5,6 +5,7 @@ package plugin import ( "fmt" + "sync" "time" "github.com/mattermost/mattermost-server/mlog" @@ -19,9 +20,10 @@ const ( ) type PluginHealthCheckJob struct { - cancel chan struct{} - cancelled chan struct{} - env *Environment + cancel chan struct{} + cancelled chan struct{} + cancelOnce sync.Once + env *Environment } // InitPluginHealthCheckJob starts a new job if one is not running and is set to enabled, or kills an existing one if set to disabled. @@ -125,7 +127,9 @@ func newPluginHealthCheckJob(env *Environment) *PluginHealthCheckJob { } func (job *PluginHealthCheckJob) Cancel() { - close(job.cancel) + job.cancelOnce.Do(func() { + close(job.cancel) + }) <-job.cancelled }