mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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 <anusha@docker.com>
This commit is contained in:
parent
2c50035f93
commit
57499fa62e
2 changed files with 15 additions and 10 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue