From 48e6137f469f6130181cb4c3171b8ba8b4ac1358 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Mon, 7 Oct 2013 23:21:39 -0700 Subject: [PATCH] fix node.go race between expire and update --- store/node.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/store/node.go b/store/node.go index 547e1aed8..158378199 100644 --- a/store/node.go +++ b/store/node.go @@ -279,14 +279,21 @@ func (n *Node) Expire(s *Store) { // if timeout, delete the node case <-time.After(duration): + // before expire get the lock, the expiration time + // of the node may be updated. + // we have to check again when get the lock s.worldLock.Lock() defer s.worldLock.Unlock() - e := newEvent(Expire, n.Path, UndefIndex, UndefTerm) - s.WatcherHub.notify(e) + expired, _ := n.IsExpired() - n.Remove(true, nil) - s.Stats.Inc(ExpireCount) + if expired { + e := newEvent(Expire, n.Path, UndefIndex, UndefTerm) + s.WatcherHub.notify(e) + + n.Remove(true, nil) + s.Stats.Inc(ExpireCount) + } return