diff --git a/libnetwork/endpoint.go b/libnetwork/endpoint.go index b0aacb9f44..c303e91a28 100644 --- a/libnetwork/endpoint.go +++ b/libnetwork/endpoint.go @@ -1000,5 +1000,17 @@ func (c *controller) cleanupLocalEndpoints() { log.Warnf("Could not delete local endpoint %s during endpoint cleanup: %v", ep.name, err) } } + + epl, err = n.getEndpointsFromStore() + if err != nil { + log.Warnf("Could not get list of endpoints in network %s for count update: %v", n.name, err) + continue + } + + epCnt := n.getEpCnt().EndpointCnt() + if epCnt != uint64(len(epl)) { + log.Warnf("Inconsistent endpoint_cnt for network %s. Expected=%d, Actual=%d", n.name, len(epl), epCnt) + n.getEpCnt().setCnt(uint64(len(epl))) + } } } diff --git a/libnetwork/endpoint_cnt.go b/libnetwork/endpoint_cnt.go index 507de393b8..702fbac8d7 100644 --- a/libnetwork/endpoint_cnt.go +++ b/libnetwork/endpoint_cnt.go @@ -123,6 +123,13 @@ func (ec *endpointCnt) updateStore() error { } } +func (ec *endpointCnt) setCnt(cnt uint64) error { + ec.Lock() + ec.Count = cnt + ec.Unlock() + return ec.updateStore() +} + func (ec *endpointCnt) atomicIncDecEpCnt(inc bool) error { retry: ec.Lock()