From 77280a87b70d3b2b629cd30ea93464287f346fa1 Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Sun, 24 May 2015 22:26:50 +0200 Subject: [PATCH 1/2] Fix race in stats cli and native driver Signed-off-by: Antonio Murdaca --- api/client/stats.go | 2 ++ daemon/execdriver/native/driver.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/api/client/stats.go b/api/client/stats.go index 332b78003b..ba56982b9e 100644 --- a/api/client/stats.go +++ b/api/client/stats.go @@ -37,7 +37,9 @@ func (s *containerStats) Collect(cli *DockerCli, streamStats bool) { } stream, _, err := cli.call("GET", "/containers/"+s.Name+"/stats?"+v.Encode(), nil, nil) if err != nil { + s.mu.Lock() s.err = err + s.mu.Unlock() return } defer stream.Close() diff --git a/daemon/execdriver/native/driver.go b/daemon/execdriver/native/driver.go index 1e1df1f21b..67b6987166 100644 --- a/daemon/execdriver/native/driver.go +++ b/daemon/execdriver/native/driver.go @@ -335,7 +335,9 @@ func (d *driver) Clean(id string) error { } func (d *driver) Stats(id string) (*execdriver.ResourceStats, error) { + d.Lock() c := d.activeContainers[id] + d.Unlock() if c == nil { return nil, execdriver.ErrNotRunning } From 9e425d56d0ec7d3343dd309500a7fe6e36648f2b Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Tue, 26 May 2015 13:54:53 +0200 Subject: [PATCH 2/2] Add lock before accessing native driver active containers Signed-off-by: Antonio Murdaca --- daemon/execdriver/native/driver.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/daemon/execdriver/native/driver.go b/daemon/execdriver/native/driver.go index 67b6987166..4da3e34382 100644 --- a/daemon/execdriver/native/driver.go +++ b/daemon/execdriver/native/driver.go @@ -259,7 +259,9 @@ func (d *driver) Kill(c *execdriver.Command, sig int) error { } func (d *driver) Pause(c *execdriver.Command) error { + d.Lock() active := d.activeContainers[c.ID] + d.Unlock() if active == nil { return fmt.Errorf("active container for %s does not exist", c.ID) } @@ -267,7 +269,9 @@ func (d *driver) Pause(c *execdriver.Command) error { } func (d *driver) Unpause(c *execdriver.Command) error { + d.Lock() active := d.activeContainers[c.ID] + d.Unlock() if active == nil { return fmt.Errorf("active container for %s does not exist", c.ID) }