Browse Source

fix node.go race between expire and update

Xiang Li 12 years ago
parent
commit
48e6137f46
1 changed files with 11 additions and 4 deletions
  1. 11 4
      store/node.go

+ 11 - 4
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