Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request #935 from bcwaldon/933
Browse files Browse the repository at this point in the history
Only set up expiration channel if necessary
  • Loading branch information
bcwaldon committed Oct 2, 2014
2 parents 48cc9df + b7b130d commit f010db9
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,6 @@ func acquireLeadership(lReg registry.LeaseRegistry, machID string, ver int, ttl
return l
}

rem := existing.TimeRemaining()
expire := time.NewTicker(rem)

// call Stop to speed up garbage collection in the event
// that the Lease cannot be stolen
defer expire.Stop()

if existing.Version() >= ver {
log.V(1).Infof("Lease already held by Machine(%s) operating at acceptable version %d", existing.MachineID(), existing.Version())
return nil
Expand All @@ -173,9 +166,10 @@ func acquireLeadership(lReg registry.LeaseRegistry, machID string, ver int, ttl

log.Infof("Stole engine leadership from Machine(%s)", existing.MachineID())

rem := existing.TimeRemaining()
if rem > 0 {
log.Infof("Waiting %v for previous lease to expire before continuing reconciliation", rem)
<-expire.C
<-time.After(rem)
}

return l
Expand Down

0 comments on commit f010db9

Please sign in to comment.