From d72849e8a16de503656bea47740913d06074183f 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 6d5f4a703..4e6854885 100644 --- a/memberlist.go +++ b/memberlist.go @@ -658,6 +658,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.") @@ -669,9 +671,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)