Ver código fonte

lease: store server-decided TTL in lease

If actual TTL is not stored in lease, the client will receive the correct
TTL and therefore won't be able to keepalive correctly.
Anthony Romano 10 anos atrás
pai
commit
be7d573366
1 arquivos alterados com 5 adições e 4 exclusões
  1. 5 4
      lease/lessor.go

+ 5 - 4
lease/lessor.go

@@ -413,16 +413,17 @@ func (l Lease) removeFrom(b backend.Backend) {
 // refresh refreshes the expiry of the lease. It extends the expiry at least
 // refresh refreshes the expiry of the lease. It extends the expiry at least
 // minLeaseTTL second.
 // minLeaseTTL second.
 func (l *Lease) refresh() {
 func (l *Lease) refresh() {
-	ttl := l.TTL
 	if l.TTL < minLeaseTTL {
 	if l.TTL < minLeaseTTL {
-		ttl = minLeaseTTL
+		l.TTL = minLeaseTTL
 	}
 	}
-
-	l.expiry = time.Now().Add(time.Second * time.Duration(ttl))
+	l.expiry = time.Now().Add(time.Second * time.Duration(l.TTL))
 }
 }
 
 
 // forever sets the expiry of lease to be forever.
 // forever sets the expiry of lease to be forever.
 func (l *Lease) forever() {
 func (l *Lease) forever() {
+	if l.TTL < minLeaseTTL {
+		l.TTL = minLeaseTTL
+	}
 	l.expiry = forever
 	l.expiry = forever
 }
 }