Merge pull request #15921 from srust/volume_driver_register_retry

Retry registering a volume driver
This commit is contained in:
David Calavera 2015-09-02 11:24:52 +02:00
commit 2c6dacda2e

View file

@ -25,6 +25,7 @@ package plugins
import ( import (
"errors" "errors"
"sync" "sync"
"time"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/docker/pkg/tlsconfig" "github.com/docker/docker/pkg/tlsconfig"
@ -109,27 +110,45 @@ func (p *Plugin) activateWithLock() error {
} }
func load(name string) (*Plugin, error) { func load(name string) (*Plugin, error) {
storage.Lock() return loadWithRetry(name, true)
}
func loadWithRetry(name string, retry bool) (*Plugin, error) {
registry := newLocalRegistry() registry := newLocalRegistry()
pl, err := registry.Plugin(name) start := time.Now()
if err == nil {
storage.plugins[name] = pl
}
storage.Unlock()
if err != nil { var retries int
return nil, err for {
} pl, err := registry.Plugin(name)
if err != nil {
if !retry {
return nil, err
}
err = pl.activate() timeOff := backoff(retries)
if abort(start, timeOff) {
return nil, err
}
retries++
logrus.Warnf("Unable to locate plugin: %s, retrying in %v", name, timeOff)
time.Sleep(timeOff)
continue
}
if err != nil {
storage.Lock() storage.Lock()
delete(storage.plugins, name) storage.plugins[name] = pl
storage.Unlock() storage.Unlock()
}
return pl, err err = pl.activate()
if err != nil {
storage.Lock()
delete(storage.plugins, name)
storage.Unlock()
}
return pl, err
}
} }
func get(name string) (*Plugin, error) { func get(name string) (*Plugin, error) {