From 2ef78af0ca86af9336cf61d1b7d88ab7eec692ce Mon Sep 17 00:00:00 2001 From: Todd Gruben Date: Thu, 26 Apr 2018 10:42:50 -0500 Subject: [PATCH] adjusted protection around cluster coordinator mutations --- cluster.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cluster.go b/cluster.go index c9f5fd9a8..c7285d17a 100644 --- a/cluster.go +++ b/cluster.go @@ -315,7 +315,7 @@ func (c *Cluster) SetCoordinator(n *Node) error { } // Update IsCoordinator on all nodes (locally). - _ = c.UpdateCoordinator(n) + _ = c.updateCoordinator(n) // Send the update coordinator message to all nodes. err := c.Broadcaster.SendSync( @@ -335,6 +335,12 @@ func (c *Cluster) SetCoordinator(n *Node) error { // to true, and sets all other nodes to false. Returns true if the value // changed. func (c *Cluster) UpdateCoordinator(n *Node) bool { + c.mu.Lock() + defer c.mu.Unlock() + _ = c.updateCoordinator(n) +} + +func (c *Cluster) updateCoordinator(n *Node) bool { var changed bool if c.Coordinator != n.ID { c.Coordinator = n.ID