From c04cae5bf049c749923d5644c970d455509a5b9b Mon Sep 17 00:00:00 2001 From: Sun Hongliang Date: Thu, 24 Mar 2016 00:24:01 +0800 Subject: [PATCH] add read lock for eventsHandler when only it is necessary. Signed-off-by: Sun Hongliang --- api/events.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/events.go b/api/events.go index 8a289608c9..46128030a9 100644 --- a/api/events.go +++ b/api/events.go @@ -73,8 +73,6 @@ func (eh *eventsHandler) cleanupHandler(remoteAddr string) { // Handle writes information about a cluster event to each remote address in the cluster that has been added to the events handler. // After an unsuccessful write to a remote address, the associated channel is closed and the address is removed from the events handler. func (eh *eventsHandler) Handle(e *cluster.Event) error { - eh.RLock() - // remove this hack once 1.10 is broadly adopted from := e.From e.From = e.From + " node:" + e.Engine.Name @@ -109,6 +107,8 @@ func (eh *eventsHandler) Handle(e *cluster.Event) error { var failed []string + eh.RLock() + for key, w := range eh.ws { if _, err := fmt.Fprintf(w, string(data)); err != nil { // collect them to handle later under Lock