This repository has been archived by the owner on Mar 9, 2019. It is now read-only.
Cleanup file descriptors on failed database initialization #725
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 returnsnil
and the error. Which makes sense; you've opened (and created) the file with theO_RDONLY
flag 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.