Skip to content

Commit

Permalink
fix missing channel init
Browse files Browse the repository at this point in the history
  • Loading branch information
srene committed Sep 19, 2024
1 parent ce9cc94 commit 5c404e1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions store/badger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package store
import (
"errors"
"path/filepath"
"sync"
"time"

"github.com/dymensionxyz/dymint/types"
Expand All @@ -25,8 +26,9 @@ var (

// BadgerKV is a implementation of KVStore using Badger v3.
type BadgerKV struct {
db *badger.DB
closing chan struct{}
db *badger.DB
closing chan struct{}
closeOnce sync.Once
}

// NewDefaultInMemoryKVStore builds KVStore that works in-memory (without accessing disk).
Expand All @@ -49,7 +51,8 @@ func NewKVStore(rootDir, dbPath, dbName string, syncWrites bool, logger types.Lo
panic(err)
}
b := &BadgerKV{
db: db,
db: db,
closing: make(chan struct{}),
}
go b.gc(gcTimeout, discardRatio, logger)

Check notice

Code scanning / CodeQL

Spawning a Go routine Note

Spawning a Go routine may be a possible source of non-determinism
return b
Expand All @@ -70,7 +73,9 @@ func Rootify(rootDir, dbPath string) string {

// Close implements KVStore.
func (b *BadgerKV) Close() error {
close(b.closing)
b.closeOnce.Do(func() {
close(b.closing)
})
return b.db.Close()
}

Expand Down

0 comments on commit 5c404e1

Please sign in to comment.