https://bugs.openldap.org/show_bug.cgi?id=9278
--- Comment #2 from Howard Chu hyc@openldap.org --- Please specify the version of liblmdb you were using.
(In reply to Xin Li from comment #0)
The attached lmdb.diff is a possible workaround for this (it would skip unmapping when setting up the robust mutex for the first time).
The patch is clearly invalid. The region must be unmapped when the environment is closed. The same would happen anyway, if the process were to exit.
Once the last process closes the environment, all of the contents of the lockfile become invalid anyway, so the FreeBSD cleanup is the expected and correct action. On the next call to env_open, when we see that no other process has it open already, the lockfile is reinitialized and those mutexes are completely created again. If a second process is coming in at this point and getting EINVAL on those mutexes, that means that the mutex initialization screwed up somehow, which sounds like a FreeBSD bug.