2018-04-24 15:50:26 +00:00
|
|
|
diff --git i/ethdb/database.go w/ethdb/database.go
|
|
|
|
index 001d8f0bb..4c9b1412c 100644
|
|
|
|
--- i/ethdb/database.go
|
|
|
|
+++ w/ethdb/database.go
|
|
|
|
@@ -55,6 +55,7 @@ type LDBDatabase struct {
|
|
|
|
|
|
|
|
quitLock sync.Mutex // Mutex protecting the quit channel access
|
|
|
|
quitChan chan chan error // Quit channel to stop the metrics collection before closing the database
|
|
|
|
+ wg sync.WaitGroup // WaitGroup waits till all metering collections will exit.
|
|
|
|
|
|
|
|
log log.Logger // Contextual logger tracking the database path
|
|
|
|
}
|
|
|
|
@@ -134,14 +135,11 @@ func (db *LDBDatabase) Close() {
|
|
|
|
// Stop the metrics collection to avoid internal database races
|
|
|
|
db.quitLock.Lock()
|
|
|
|
defer db.quitLock.Unlock()
|
|
|
|
-
|
|
|
|
if db.quitChan != nil {
|
|
|
|
- errc := make(chan error)
|
|
|
|
- db.quitChan <- errc
|
|
|
|
- if err := <-errc; err != nil {
|
|
|
|
- db.log.Error("Metrics collection failed", "err", err)
|
|
|
|
- }
|
|
|
|
+ close(db.quitChan)
|
|
|
|
}
|
|
|
|
+ db.wg.Wait()
|
|
|
|
+ db.quitChan = nil
|
|
|
|
err := db.db.Close()
|
|
|
|
if err == nil {
|
|
|
|
db.log.Info("Database closed")
|
|
|
|
@@ -173,7 +171,11 @@ func (db *LDBDatabase) Meter(prefix string) {
|
|
|
|
db.quitChan = make(chan chan error)
|
|
|
|
db.quitLock.Unlock()
|
|
|
|
|
|
|
|
- go db.meter(3 * time.Second)
|
|
|
|
+ db.wg.Add(1)
|
|
|
|
+ go func() {
|
2018-05-03 08:03:42 +00:00
|
|
|
+ defer db.wg.Done()
|
2018-04-24 15:50:26 +00:00
|
|
|
+ db.meter(3 * time.Second)
|
|
|
|
+ }()
|
|
|
|
}
|
|
|
|
|
|
|
|
// meter periodically retrieves internal leveldb counters and reports them to
|
2018-05-03 08:03:42 +00:00
|
|
|
@@ -345,9 +347,8 @@ func (db *LDBDatabase) meter(refresh tim
|
|
|
|
|
|
|
|
// Sleep a bit, then repeat the stats collection
|
|
|
|
select {
|
|
|
|
- case errc := <-db.quitChan:
|
|
|
|
+ case <-db.quitChan:
|
|
|
|
// Quit requesting, stop hammering the database
|
|
|
|
- errc <- nil
|
|
|
|
return
|
|
|
|
|
|
|
|
case <-time.After(refresh):
|