From 46077fcfb13008dd8692c4be5180104dfbfe5e39 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Mon, 7 Dec 2015 14:20:13 -0800 Subject: [PATCH] Fix mutex copy If we use peerMap as value, then we copy its mutex on `pMap = d.peerDb.mp[nid]` and lock entirely different mutexes every time. Signed-off-by: Alexander Morozov --- libnetwork/drivers/overlay/overlay.go | 2 +- libnetwork/drivers/overlay/peerdb.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libnetwork/drivers/overlay/overlay.go b/libnetwork/drivers/overlay/overlay.go index 982310d7a2..9e5eba4013 100644 --- a/libnetwork/drivers/overlay/overlay.go +++ b/libnetwork/drivers/overlay/overlay.go @@ -51,7 +51,7 @@ func Init(dc driverapi.DriverCallback, config map[string]interface{}) error { d := &driver{ networks: networkTable{}, peerDb: peerNetworkMap{ - mp: map[string]peerMap{}, + mp: map[string]*peerMap{}, }, config: config, } diff --git a/libnetwork/drivers/overlay/peerdb.go b/libnetwork/drivers/overlay/peerdb.go index 22a677d8ba..c820da9f05 100644 --- a/libnetwork/drivers/overlay/peerdb.go +++ b/libnetwork/drivers/overlay/peerdb.go @@ -26,7 +26,7 @@ type peerMap struct { } type peerNetworkMap struct { - mp map[string]peerMap + mp map[string]*peerMap sync.Mutex } @@ -138,7 +138,7 @@ func (d *driver) peerDbAdd(nid, eid string, peerIP net.IP, peerIPMask net.IPMask d.peerDb.Lock() pMap, ok := d.peerDb.mp[nid] if !ok { - d.peerDb.mp[nid] = peerMap{ + d.peerDb.mp[nid] = &peerMap{ mp: make(map[string]peerEntry), }