mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
improved OnDeactivate handling (#11988)
* Deactivate plugins in parallel to improve shutdown time * Give plugins at most 10s to handle OnDeactivate before forcefully terminating
This commit is contained in:
@@ -288,16 +288,42 @@ func (env *Environment) Shutdown() {
|
||||
env.pluginHealthCheckJob.Cancel()
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
env.registeredPlugins.Range(func(key, value interface{}) bool {
|
||||
rp := value.(*registeredPlugin)
|
||||
|
||||
if rp.supervisor != nil {
|
||||
if rp.supervisor == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
|
||||
done := make(chan bool)
|
||||
go func() {
|
||||
defer close(done)
|
||||
if err := rp.supervisor.Hooks().OnDeactivate(); err != nil {
|
||||
env.logger.Error("Plugin OnDeactivate() error", mlog.String("plugin_id", rp.BundleInfo.Manifest.Id), mlog.Err(err))
|
||||
}
|
||||
rp.supervisor.Shutdown()
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
select {
|
||||
case <-time.After(10 * time.Second):
|
||||
env.logger.Warn("Plugin OnDeactivate() failed to complete in 10 seconds", mlog.String("plugin_id", rp.BundleInfo.Manifest.Id))
|
||||
case <-done:
|
||||
}
|
||||
|
||||
rp.supervisor.Shutdown()
|
||||
}()
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
wg.Wait()
|
||||
|
||||
env.registeredPlugins.Range(func(key, value interface{}) bool {
|
||||
env.registeredPlugins.Delete(key)
|
||||
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user