boltdb / bolt

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

prevent segfault after mmap failure #707

Closed lukechampine closed 6 years ago

lukechampine commented 7 years ago

Fixes #706.

This PR causes the db to revert to mmap(db, db.datasz) if the call to mmap(db, minsz) fails. The original error is still returned, so callers will see "mmap failure" returned from db.Update. I also wrapped this error in a new type, so that callers can check for it explicitly. This is good to have, since I imagine applications will want to panic instead of continuing to attempt more db.Update calls. Another option would be to add a PanicOnFailedMmap flag so that bolt will automatically panic under these conditions.

I'm not 100% sure that this code is safe, but I've confirmed that it resolves the segfault bug, and it appears that calls to db.View will succeed even after mmap failure.