From bc70ed60cb007db40b136aa75830b9b7de744465 Mon Sep 17 00:00:00 2001 From: Jana Radhakrishnan Date: Thu, 28 May 2015 23:29:21 +0000 Subject: [PATCH] Fix miscellaneaus data races Fixed the remaining data races in the libnetwork code. Signed-off-by: Jana Radhakrishnan --- libnetwork/network.go | 9 +++++++++ libnetwork/sandbox/namespace_linux.go | 6 +++++- libnetwork/sandbox/sandbox_linux_test.go | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/libnetwork/network.go b/libnetwork/network.go index 7b15ffc9fa..8a25b845b2 100644 --- a/libnetwork/network.go +++ b/libnetwork/network.go @@ -64,14 +64,23 @@ type network struct { } func (n *network) Name() string { + n.Lock() + defer n.Unlock() + return n.name } func (n *network) ID() string { + n.Lock() + defer n.Unlock() + return string(n.id) } func (n *network) Type() string { + n.Lock() + defer n.Unlock() + if n.driver == nil { return "" } diff --git a/libnetwork/sandbox/namespace_linux.go b/libnetwork/sandbox/namespace_linux.go index 97ea548ca2..3db3a8ee0f 100644 --- a/libnetwork/sandbox/namespace_linux.go +++ b/libnetwork/sandbox/namespace_linux.go @@ -52,7 +52,11 @@ func createBasePath() { } func removeUnusedPaths() { - for range time.Tick(gpmCleanupPeriod) { + gpmLock.Lock() + period := gpmCleanupPeriod + gpmLock.Unlock() + + for range time.Tick(period) { gpmLock.Lock() pathList := make([]string, 0, len(garbagePathMap)) for path := range garbagePathMap { diff --git a/libnetwork/sandbox/sandbox_linux_test.go b/libnetwork/sandbox/sandbox_linux_test.go index 2700635352..b00d14f350 100644 --- a/libnetwork/sandbox/sandbox_linux_test.go +++ b/libnetwork/sandbox/sandbox_linux_test.go @@ -33,7 +33,9 @@ func newKey(t *testing.T) (string, error) { } // Set the rpmCleanupPeriod to be low to make the test run quicker + gpmLock.Lock() gpmCleanupPeriod = 2 * time.Second + gpmLock.Unlock() return name, nil }