Skip to content

Commit e419b9a

Browse files
committed
core, p2p/discv5: fix leaked goroutines
similar to ethereum#15696
1 parent 9d187f0 commit e419b9a

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

core/blockchain.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,10 +1196,11 @@ func (bc *BlockChain) PostChainEvents(events []interface{}, logs []*types.Log) {
11961196
}
11971197

11981198
func (bc *BlockChain) update() {
1199-
futureTimer := time.Tick(5 * time.Second)
1199+
futureTimer := time.NewTicker(5 * time.Second)
1200+
defer futureTimer.Stop()
12001201
for {
12011202
select {
1202-
case <-futureTimer:
1203+
case <-futureTimer.C:
12031204
bc.procFutureBlocks()
12041205
case <-bc.quit:
12051206
return

p2p/discv5/database.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,14 @@ func (db *nodeDB) ensureExpirer() {
239239
// expirer should be started in a go routine, and is responsible for looping ad
240240
// infinitum and dropping stale data from the database.
241241
func (db *nodeDB) expirer() {
242-
tick := time.Tick(nodeDBCleanupCycle)
242+
tick := time.NewTicker(nodeDBCleanupCycle)
243+
defer tick.Stop()
243244
for {
244245
select {
245-
case <-tick:
246+
case <-tick.C:
246247
if err := db.expireNodes(); err != nil {
247248
log.Error(fmt.Sprintf("Failed to expire nodedb items: %v", err))
248249
}
249-
250250
case <-db.quit:
251251
return
252252
}

0 commit comments

Comments
 (0)