filecoin-project / lotus

Reference implementation of the Filecoin protocol, written in Go
https://lotus.filecoin.io/
Other
2.85k stars 1.27k forks source link

[BUG] Badger blockstore is not safe if closed while in use #5795

Open Stebalien opened 3 years ago

Stebalien commented 3 years ago

The badger blockstore has a state field to record whether or not the badger database is closed. Unfortunately, either:

  1. There's no way the blockstore will be closed concurrently with other operations. In this case, there's no need for the field to be atomic.
  2. The blockstore can be concurrently closed with other operations. In this case, the atomic is insufficient as we may:
    1. Thread A: See that the database is open.
    2. Thread B: Close the database.
    3. Thread A: Use the database. Badger likes to panic in this case.

Unless we have a really good reason not to, we should just use a RWMutex (like we do in go-ds-badger). If we do have a really good reason, we should figure out what we actually need here.

shuang-x-zhao-qq commented 1 year ago

Hello,i want to check with you guys whether we have a fix of this concurrent blockstore writing problem, i think our lotus client met this problem when we synced data, like below:

2023-04-09T06:56:58.022+0800 ERROR chainstore store/coalescer.go:213 error dispatching coalesced head change notification: 5 errors occurred: