Merge pull request #900 from unihorn/fix-timer

server: fix timer leak
This commit is contained in:
Xiang Li 2014-07-21 16:37:04 -07:00
commit bdeb96be0f
2 changed files with 13 additions and 13 deletions

View File

@ -772,9 +772,9 @@ func (s *PeerServer) startRoutine(f func()) {
func (s *PeerServer) monitorSnapshot() {
for {
timer := time.NewTimer(s.snapConf.checkingInterval)
defer timer.Stop()
select {
case <-s.closeChan:
timer.Stop()
return
case <-timer.C:
}
@ -807,6 +807,8 @@ func (s *PeerServer) monitorSync() {
// monitorTimeoutThreshold groups timeout threshold events together and prints
// them as a single log line.
func (s *PeerServer) monitorTimeoutThreshold() {
ticker := time.NewTicker(ThresholdMonitorTimeout)
defer ticker.Stop()
for {
select {
case <-s.closeChan:
@ -815,12 +817,10 @@ func (s *PeerServer) monitorTimeoutThreshold() {
log.Infof("%s: warning: heartbeat near election timeout: %v", s.Config.Name, value)
}
timer := time.NewTimer(ThresholdMonitorTimeout)
defer timer.Stop()
select {
case <-s.closeChan:
return
case <-timer.C:
case <-ticker.C:
}
}
}
@ -828,13 +828,13 @@ func (s *PeerServer) monitorTimeoutThreshold() {
// monitorActiveSize has the leader periodically check the status of cluster
// nodes and swaps them out for standbys as needed.
func (s *PeerServer) monitorActiveSize() {
ticker := time.NewTicker(ActiveMonitorTimeout)
defer ticker.Stop()
for {
timer := time.NewTimer(ActiveMonitorTimeout)
defer timer.Stop()
select {
case <-s.closeChan:
return
case <-timer.C:
case <-ticker.C:
}
// Ignore while this peer is not a leader.
@ -864,13 +864,13 @@ func (s *PeerServer) monitorActiveSize() {
// monitorPeerActivity has the leader periodically for dead nodes and demotes them.
func (s *PeerServer) monitorPeerActivity() {
ticker := time.NewTicker(PeerActivityMonitorTimeout)
defer ticker.Stop()
for {
timer := time.NewTimer(PeerActivityMonitorTimeout)
defer timer.Stop()
select {
case <-s.closeChan:
return
case <-timer.C:
case <-ticker.C:
}
// Ignore while this peer is not a leader.

View File

@ -178,13 +178,13 @@ func (s *StandbyServer) redirectRequests(w http.ResponseWriter, r *http.Request)
// monitorCluster assumes that the machine has tried to join the cluster and
// failed, so it waits for the interval at the beginning.
func (s *StandbyServer) monitorCluster() {
ticker := time.NewTicker(time.Duration(int64(s.SyncInterval * float64(time.Second))))
defer ticker.Stop()
for {
timer := time.NewTimer(time.Duration(int64(s.SyncInterval * float64(time.Second))))
defer timer.Stop()
select {
case <-s.closeChan:
return
case <-timer.C:
case <-ticker.C:
}
if err := s.syncCluster(nil); err != nil {