mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
fix node.go race between expire and update
This commit is contained in:
parent
a07802a347
commit
48e6137f46
@ -279,14 +279,21 @@ func (n *Node) Expire(s *Store) {
|
|||||||
// if timeout, delete the node
|
// if timeout, delete the node
|
||||||
case <-time.After(duration):
|
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()
|
s.worldLock.Lock()
|
||||||
defer s.worldLock.Unlock()
|
defer s.worldLock.Unlock()
|
||||||
|
|
||||||
e := newEvent(Expire, n.Path, UndefIndex, UndefTerm)
|
expired, _ := n.IsExpired()
|
||||||
s.WatcherHub.notify(e)
|
|
||||||
|
|
||||||
n.Remove(true, nil)
|
if expired {
|
||||||
s.Stats.Inc(ExpireCount)
|
e := newEvent(Expire, n.Path, UndefIndex, UndefTerm)
|
||||||
|
s.WatcherHub.notify(e)
|
||||||
|
|
||||||
|
n.Remove(true, nil)
|
||||||
|
s.Stats.Inc(ExpireCount)
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user