From 1f014866002170bb0d36100d63f46998dca2050b Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Tue, 13 Sep 2016 13:58:25 -0700 Subject: [PATCH] Add lock around container state access Signed-off-by: Mrunal Patel --- oci/oci.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/oci/oci.go b/oci/oci.go index 9d875211..f456a23b 100644 --- a/oci/oci.go +++ b/oci/oci.go @@ -8,6 +8,7 @@ import ( "os/exec" "path/filepath" "strings" + "sync" "time" "github.com/kubernetes-incubator/ocid/utils" @@ -93,6 +94,8 @@ func (r *Runtime) DeleteContainer(c *Container) error { // updateStatus refreshes the status of the container. func (r *Runtime) UpdateStatus(c *Container) error { + c.stateLock.Lock() + defer c.stateLock.Unlock() out, err := exec.Command(r.path, "state", c.name).Output() if err != nil { return fmt.Errorf("error getting container state for %s: %s", c.name, err) @@ -106,6 +109,8 @@ func (r *Runtime) UpdateStatus(c *Container) error { // ContainerStatus returns the state of a container. func (r *Runtime) ContainerStatus(c *Container) *ContainerState { + c.stateLock.Lock() + defer c.stateLock.Unlock() return c.state } @@ -117,6 +122,7 @@ type Container struct { labels map[string]string sandbox string state *ContainerState + stateLock sync.Mutex } // ContainerStatus represents the status of a container.