From 0c1a125644f4626b294cdd4b5862a728b1d974a7 Mon Sep 17 00:00:00 2001 From: Steffen Butzer Date: Sun, 27 Jun 2021 11:56:03 +0200 Subject: [PATCH] libnetwork: processEndpointCreate: Fix deadlock between getSvcRecords and processEndpointCreate References https://github.com/moby/moby/pull/42545 Signed-off-by: Steffen Butzer --- libnetwork/store.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libnetwork/store.go b/libnetwork/store.go index 65ae281fad..7a8dcad0a3 100644 --- a/libnetwork/store.go +++ b/libnetwork/store.go @@ -340,8 +340,11 @@ func (c *controller) processEndpointCreate(nmap map[string]*netWatch, ep *endpoi return } + networkID := n.ID() + endpointID := ep.ID() + c.Lock() - nw, ok := nmap[n.ID()] + nw, ok := nmap[networkID] c.Unlock() if ok { @@ -349,12 +352,12 @@ func (c *controller) processEndpointCreate(nmap map[string]*netWatch, ep *endpoi n.updateSvcRecord(ep, c.getLocalEps(nw), true) c.Lock() - nw.localEps[ep.ID()] = ep + nw.localEps[endpointID] = ep // If we had learned that from the kv store remove it // from remote ep list now that we know that this is // indeed a local endpoint - delete(nw.remoteEps, ep.ID()) + delete(nw.remoteEps, endpointID) c.Unlock() return } @@ -370,8 +373,8 @@ func (c *controller) processEndpointCreate(nmap map[string]*netWatch, ep *endpoi n.updateSvcRecord(ep, c.getLocalEps(nw), true) c.Lock() - nw.localEps[ep.ID()] = ep - nmap[n.ID()] = nw + nw.localEps[endpointID] = ep + nmap[networkID] = nw nw.stopCh = make(chan struct{}) c.Unlock()