From 1323730eca418ed2b666dd700e59cb0a447e3ef4 Mon Sep 17 00:00:00 2001 From: Alessandro Boch Date: Fri, 7 Apr 2017 22:25:04 -0700 Subject: [PATCH] On send node envents, notify only if there are peers - Otherwise operation will unnecessarely block for five seconds. - This is particularly noticeable on graceful shutdown of daemon in one node cluster. Signed-off-by: Alessandro Boch --- libnetwork/networkdb/broadcast.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libnetwork/networkdb/broadcast.go b/libnetwork/networkdb/broadcast.go index 5555634179..3fe9f6271a 100644 --- a/libnetwork/networkdb/broadcast.go +++ b/libnetwork/networkdb/broadcast.go @@ -86,6 +86,15 @@ func (nDB *NetworkDB) sendNodeEvent(event NodeEvent_Type) error { notify: notifyCh, }) + nDB.RLock() + noPeers := len(nDB.nodes) <= 1 + nDB.RUnlock() + + // Message enqueued, do not wait for a send if no peer is present + if noPeers { + return nil + } + // Wait for the broadcast select { case <-notifyCh: