diff --git a/libnetwork/networkdb/delegate.go b/libnetwork/networkdb/delegate.go index 9aa876058f..d909bcdb42 100644 --- a/libnetwork/networkdb/delegate.go +++ b/libnetwork/networkdb/delegate.go @@ -148,13 +148,8 @@ func (nDB *NetworkDB) handleTableEvent(tEvent *TableEvent, isBulkSync bool) bool // Update our local clock if the received messages has newer time. nDB.tableClock.Witness(tEvent.LTime) - nDB.Lock() - // Hold the lock until after we broadcast the event to watchers so that - // the new watch receives either the synthesized event or the event we - // broadcast, never both. - defer nDB.Unlock() - // Ignore the table events for networks that are in the process of going away + nDB.RLock() networks := nDB.networks[nDB.config.NodeID] network, ok := networks[tEvent.NetworkID] // Check if the owner of the event is still part of the network @@ -166,12 +161,18 @@ func (nDB *NetworkDB) handleTableEvent(tEvent *TableEvent, isBulkSync bool) bool break } } + nDB.RUnlock() if !ok || network.leaving || !nodePresent { // I'm out of the network OR the event owner is not anymore part of the network so do not propagate return false } + nDB.Lock() + // Hold the lock until after we broadcast the event to watchers so that + // the new watch receives either the synthesized event or the event we + // broadcast, never both. + defer nDB.Unlock() var entryPresent bool prev, err := nDB.getEntry(tEvent.TableName, tEvent.NetworkID, tEvent.Key) if err == nil {