From bb7bce1644069d01b65e72a620c81700b1518c7a Mon Sep 17 00:00:00 2001 From: Lei Ni Date: Thu, 11 Aug 2022 08:42:52 +0000 Subject: [PATCH] fixed a data race issue see #272 --- memberlist.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/memberlist.go b/memberlist.go index 512701dee..d497ef310 100644 --- a/memberlist.go +++ b/memberlist.go @@ -654,6 +654,8 @@ func (m *Memberlist) Leave(timeout time.Duration) error { m.nodeLock.Lock() state, ok := m.nodeMap[m.config.Name] + incarnation := state.Incarnation + name := state.Name m.nodeLock.Unlock() if !ok { m.logger.Printf("[WARN] memberlist: Leave but we're not in the node map.") @@ -665,9 +667,9 @@ func (m *Memberlist) Leave(timeout time.Duration) error { // intentionally. When Node equals From, other nodes know for // sure this node is gone. d := dead{ - Incarnation: state.Incarnation, - Node: state.Name, - From: state.Name, + Incarnation: incarnation, + Node: name, + From: name, } m.deadNode(&d)