Fix race condition in execCommandGC

`daemon.execCommandGC`
The daemon object (grep execCommandGC) iterate over a map
(grep execCommands.Commands) in a goroutine.
Lock can't protect concurrency access in this case.
Exec command storage object should return a copy of commands instead.

Signed-off-by: Pei Su <sillyousu@gmail.com>
Upstream-commit: e5e62b96ce0d4eb3934a386b07203830f55e07ce
Component: engine
This commit is contained in:
Pei Su
2016-01-19 20:30:48 +08:00
parent bea0f479a8
commit 818faba77e

View File

@ -53,7 +53,13 @@ func NewStore() *Store {
// Commands returns the exec configurations in the store.
func (e *Store) Commands() map[string]*Config {
return e.commands
e.RLock()
commands := make(map[string]*Config, len(e.commands))
for id, config := range e.commands {
commands[id] = config
}
e.RUnlock()
return commands
}
// Add adds a new exec configuration to the store.