[#598] Fix use-after-close bug in badger writecache

Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
This commit is contained in:
Alejandro Lopez 2023-08-14 10:54:09 +03:00 committed by Evgenii Stratonikov
parent ae8be495c8
commit 88b6755c5e
2 changed files with 15 additions and 0 deletions

View file

@ -80,6 +80,13 @@ func (c *cache) flushSmallObjects() {
continue
}
// Using the db after Close will panic and badger won't wait for outstanding txs,
// so we need to check manually.
if c.db.IsClosed() {
c.modeMtx.RUnlock()
return
}
_ = c.db.View(func(tx *badger.Txn) error {
it := tx.NewIterator(badger.DefaultIteratorOptions)
defer it.Close()