mirror of
https://github.com/etcd-io/bbolt.git
synced 2025-07-12 23:28:15 +00:00
Clean up file descriptors on failed database initialization
Fixes an issue where failing to open a non-existent database in ReadOnly mode would make you unable to properly initialize it in ReadWrite mode afterwards due to a hanging lock.
This commit is contained in:
parent
d57ee90507
commit
818c231b78
3
db.go
3
db.go
@ -213,10 +213,13 @@ func Open(path string, mode os.FileMode, options *Options) (*DB, error) {
|
||||
|
||||
// Initialize the database if it doesn't exist.
|
||||
if info, err := db.file.Stat(); err != nil {
|
||||
_ = db.close()
|
||||
return nil, err
|
||||
} else if info.Size() == 0 {
|
||||
// Initialize new files with meta pages.
|
||||
if err := db.init(); err != nil {
|
||||
// clean up file descriptor on initialization fail
|
||||
_ = db.close()
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user