fix node.go race between expire and update

This commit is contained in:
Xiang Li 2013-10-07 23:21:39 -07:00
parent a07802a347
commit 48e6137f46

View File

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