Ensure all tickers are explicitly stopped.

As pointed out in #189, according to the Go documentation, a ticker must
be stopped to release associated resources.  This commit adds a defer call
to stop two tickers there were previously not being stopped as well as
changes two others that were being stopped over to use defer so it's more
consistent.

The other ticker in ScheduleShutdown is replaced and already calls Stop
before replacing it, so it has not been modified.

Closes #189.

ok @jrick
This commit is contained in:
Dave Collins 2014-12-03 18:20:19 -06:00
parent 888884a399
commit 9c0db2f7fd
3 changed files with 4 additions and 2 deletions

View File

@ -338,6 +338,7 @@ func (a *AddrManager) getTriedBucket(netAddr *btcwire.NetAddress) int {
// as a goroutine.
func (a *AddrManager) addressHandler() {
dumpAddressTicker := time.NewTicker(dumpAddressInterval)
defer dumpAddressTicker.Stop()
out:
for {
select {
@ -348,7 +349,6 @@ out:
break out
}
}
dumpAddressTicker.Stop()
a.savePeers()
a.wg.Done()
log.Trace("Address handler done")

View File

@ -72,6 +72,7 @@ func (m *CPUMiner) speedMonitor() {
var hashesPerSec float64
var totalHashes uint64
ticker := time.NewTicker(time.Second * hpsUpdateSecs)
defer ticker.Stop()
out:
for {
@ -261,6 +262,7 @@ func (m *CPUMiner) generateBlocks(quit chan struct{}) {
// Start a ticker which is used to signal checks for stale work and
// updates to the speed monitor.
ticker := time.NewTicker(time.Second * hashUpdateSecs)
defer ticker.Stop()
out:
for {
// Quit when the miner is stopped.
@ -318,7 +320,6 @@ out:
}
}
ticker.Stop()
m.workerWg.Done()
minrLog.Tracef("Generate blocks worker done")
}

View File

@ -1557,6 +1557,7 @@ func (p *peer) queueHandler() {
pendingMsgs := list.New()
invSendQueue := list.New()
trickleTicker := time.NewTicker(time.Second * 10)
defer trickleTicker.Stop()
// We keep the waiting flag so that we know if we have a message queued
// to the outHandler or not. We could use the presence of a head of