From ac382473d977b54257a27282b27843588379962c Mon Sep 17 00:00:00 2001 From: Pei Su Date: Tue, 19 Jan 2016 20:30:48 +0800 Subject: [PATCH] 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 --- daemon/exec/exec.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/daemon/exec/exec.go b/daemon/exec/exec.go index 5536623191..6941cde689 100644 --- a/daemon/exec/exec.go +++ b/daemon/exec/exec.go @@ -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.