add read lock for eventsHandler when only it is necessary.

Signed-off-by: Sun Hongliang <allen.sun@daocloud.io>
This commit is contained in:
Sun Hongliang 2016-03-24 00:24:01 +08:00
parent ef1c777887
commit c04cae5bf0
1 changed files with 2 additions and 2 deletions

View File

@ -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