From 7ddb40239bed22774c0341c572f22ed34ea78f99 Mon Sep 17 00:00:00 2001 From: ucwong Date: Tue, 26 May 2020 17:03:37 +0800 Subject: [PATCH] ethdb/leveldb: use timer instead of time.After (#21066) --- ethdb/leveldb/leveldb.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ethdb/leveldb/leveldb.go b/ethdb/leveldb/leveldb.go index 7ff52e59f6..80380db325 100644 --- a/ethdb/leveldb/leveldb.go +++ b/ethdb/leveldb/leveldb.go @@ -248,6 +248,9 @@ func (db *Database) meter(refresh time.Duration) { merr error ) + timer := time.NewTimer(refresh) + defer timer.Stop() + // Iterate ad infinitum and collect the stats for i := 1; errc == nil && merr == nil; i++ { // Retrieve the database stats @@ -399,7 +402,8 @@ func (db *Database) meter(refresh time.Duration) { select { case errc = <-db.quitChan: // Quit requesting, stop hammering the database - case <-time.After(refresh): + case <-timer.C: + timer.Reset(refresh) // Timeout, gather a new set of stats } }