Fix race condition in `LDBDatabase.Close()`

- https://jenkins.status.im/job/status-go/job/race-check/54/consoleFull
This commit is contained in:
Pedro Pombeiro 2018-05-03 10:03:42 +02:00 committed by Dmitry Shulyak
parent 04fa765daf
commit acbf251a3c
2 changed files with 14 additions and 4 deletions

View File

@ -35,9 +35,20 @@ index 001d8f0bb..4c9b1412c 100644
- go db.meter(3 * time.Second)
+ db.wg.Add(1)
+ go func() {
+ db.wg.Done()
+ defer db.wg.Done()
+ db.meter(3 * time.Second)
+ }()
}
// meter periodically retrieves internal leveldb counters and reports them to
@@ -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):

View File

@ -173,7 +173,7 @@ func (db *LDBDatabase) Meter(prefix string) {
db.wg.Add(1)
go func() {
db.wg.Done()
defer db.wg.Done()
db.meter(3 * time.Second)
}()
}
@ -347,9 +347,8 @@ func (db *LDBDatabase) meter(refresh time.Duration) {
// 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):