From 57499fa62e697ea244455c5abda7ed8bc022f44c Mon Sep 17 00:00:00 2001 From: Anusha Ragunathan Date: Mon, 15 Aug 2016 09:27:36 -0700 Subject: [PATCH] When handling plugin exit, lookup plugins only during daemon shutdown. The main intent of handling plugin exit is for graceful shutdown of plugins during daemon shutdown. So avoid plugin lookup during plugin exits caused by other reasons (eg. force remove) Signed-off-by: Anusha Ragunathan --- plugin/manager.go | 18 +++++++++++------- plugin/manager_linux.go | 7 ++++--- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/plugin/manager.go b/plugin/manager.go index 1430871c79..f292c09a5e 100644 --- a/plugin/manager.go +++ b/plugin/manager.go @@ -253,20 +253,24 @@ func LookupWithCapability(name, capability string) (Plugin, error) { return nil, ErrInadequateCapability{name, capability} } -// StateChanged updates plugin internals using from libcontainerd events. +// StateChanged updates plugin internals using libcontainerd events. func (pm *Manager) StateChanged(id string, e libcontainerd.StateInfo) error { logrus.Debugf("plugin state changed %s %#v", id, e) switch e.State { case libcontainerd.StateExit: + var shutdown bool pm.RLock() - p, idOk := pm.plugins[id] + shutdown = pm.shutdown pm.RUnlock() - if !idOk { - return ErrNotFound(id) - } - if pm.shutdown == true { - p.exitChan <- true + if shutdown { + pm.RLock() + p, idOk := pm.plugins[id] + pm.RUnlock() + if !idOk { + return ErrNotFound(id) + } + close(p.exitChan) } } diff --git a/plugin/manager_linux.go b/plugin/manager_linux.go index 8542ecec67..401e4d1cdb 100644 --- a/plugin/manager_linux.go +++ b/plugin/manager_linux.go @@ -143,10 +143,12 @@ func (pm *Manager) disable(p *plugin) error { // Shutdown stops all plugins and called during daemon shutdown. func (pm *Manager) Shutdown() { + pm.Lock() + pm.shutdown = true + pm.Unlock() + pm.RLock() defer pm.RUnlock() - - pm.shutdown = true for _, p := range pm.plugins { if pm.liveRestore && p.PluginObj.Active { logrus.Debug("Plugin active when liveRestore is set, skipping shutdown") @@ -173,7 +175,6 @@ func (pm *Manager) Shutdown() { } } } - close(p.exitChan) } if err := os.RemoveAll(p.runtimeSourcePath); err != nil { logrus.Errorf("Remove plugin runtime failed with error: %v", err)