mdbx: proper atomic close (#827)

This commit is contained in:
Alex Sharov 2023-01-10 12:02:23 +07:00 committed by GitHub
parent d2d03d140b
commit 493ae8b083
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -431,10 +431,9 @@ func (db *MdbxKV) openDBIs(buckets []string) error {
// Close closes db // Close closes db
// All transactions must be closed before closing the database. // All transactions must be closed before closing the database.
func (db *MdbxKV) Close() { func (db *MdbxKV) Close() {
if db.closed.Load() { if db.closed.CompareAndSwap(false, true) {
return return
} }
db.closed.Store(true)
db.wg.Wait() db.wg.Wait()
db.env.Close() db.env.Close()
db.env = nil db.env = nil