Browse code

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>

Pei Su authored on 2016/01/19 21:30:48
Showing 1 changed files
... ...
@@ -53,7 +53,13 @@ func NewStore() *Store {
53 53
 
54 54
 // Commands returns the exec configurations in the store.
55 55
 func (e *Store) Commands() map[string]*Config {
56
-	return e.commands
56
+	e.RLock()
57
+	commands := make(map[string]*Config, len(e.commands))
58
+	for id, config := range e.commands {
59
+		commands[id] = config
60
+	}
61
+	e.RUnlock()
62
+	return commands
57 63
 }
58 64
 
59 65
 // Add adds a new exec configuration to the store.