Prevent infinite ticker leaks in kaspaminer (#1476)

* Prevent infinite tickers leaks in kaspaminer

* Reset ticker in ConnectionManager instead of allocating a new one

Co-authored-by: Ori Newman <orinewman1@gmail.com>
This commit is contained in:
Elichai Turkel 2021-02-01 14:52:17 +02:00 committed by GitHub
parent d281dabdb4
commit 280fa3de46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -167,6 +167,8 @@ func templatesLoop(client *minerClient, miningAddr util.Address,
newTemplateChan <- template
}
getBlockTemplate()
const tickerTime = 500 * time.Millisecond
ticker := time.NewTicker(tickerTime)
for {
select {
case <-stopChan:
@ -174,7 +176,8 @@ func templatesLoop(client *minerClient, miningAddr util.Address,
return
case <-client.blockAddedNotificationChan:
getBlockTemplate()
case <-time.Tick(500 * time.Millisecond):
ticker.Reset(tickerTime)
case <-ticker.C:
getBlockTemplate()
}
}

View File

@ -147,8 +147,7 @@ func (c *ConnectionManager) IsBanned(netConnection *netadapter.NetConnection) (b
func (c *ConnectionManager) waitTillNextIteration() {
select {
case <-c.resetLoopChan:
c.loopTicker.Stop()
c.loopTicker = time.NewTicker(connectionsLoopInterval)
c.loopTicker.Reset(connectionsLoopInterval)
case <-c.loopTicker.C:
}
}