boltdb / bolt

An embedded key/value database for Go.
MIT License
14.24k stars 1.51k forks source link

Cleanup file descriptors on failed database initialization #725

Closed cj-dimaggio closed 6 years ago

cj-dimaggio commented 7 years ago

Came across this one today on a Unix system...

So when you try to open up a Bolt db that doesn't exist already exist in ReadOnly mode you get an os.PathError when initializing your meta pages and Bolt returns nil and the error. Which makes sense; you've opened (and created) the file with the O_RDONLYflag and are now trying to write to it. I don't, personally, think that in ReadOnly mode you should initialize the database.

However the issue is that this happens after you've acquired your shared lock on the FD and you now have no (direct) means of releasing it (because you've been passed back only nil). So if in my program I want to handle this error by creating and initializing a new database in ReadWrite mode I can't because I hang indefinitely waiting for my exclusive lock. All that this change does is make sure we call close on our partially created database before returning, closing our file so that a subsequent call to Open has a chance of acquiring an exclusive lock on the file.

heyitsanthony commented 7 years ago

@Ssawa this patch probably won't get merged here, but I'll be happy to add it to http://github.com/coreos/bbolt

vincent-petithory commented 7 years ago

Agressive ad.

On jeu. 31 août 2017 00:48 Anthony Romano notifications@github.com wrote:

@Ssawa https://github.com/ssawa this patch probably won't get merged here, but I'll be happy to add it to http://github.com/coreos/bbolt https://github.com/coreos/bbolt

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/boltdb/bolt/pull/725#issuecomment-326140735, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGwMHmfiEWVtY1FvZPyuI2hOzSNPWQSks5sdebTgaJpZM4PGsAP .

heyitsanthony commented 7 years ago

@vincent-petithory my apologies for trying to maintain this software