Skip to content

Commit a554e07

Browse files
committed
Use POSIX mutexes for LMDB on macOS
Darwin's default System V semaphore backend fails with EINVAL once a process holds locks on more than kern.sysv.semume (=10) semaphore sets concurrently, breaking workloads that open multiple DB environments in one process (e.g. the storage-lmdb test suite). Compile lmdb with MDB_USE_POSIX_MUTEX=1 on Apple targets via target- scoped CFLAGS in .cargo/config.toml; MDB_USE_ROBUST must be disabled because Darwin does not implement robust mutexes. Linux builds keep upstream defaults.
1 parent be919bf commit a554e07

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

.cargo/config.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,18 @@ linker = "aarch64-linux-gnu-gcc"
1111

1212
[target.x86_64-pc-windows-msvc]
1313
rustflags = ["-C", "target-feature=+crt-static"]
14+
15+
# Force lmdb-sys (lmdb-mintlayer fork) to use POSIX mutexes instead of System V
16+
# semaphores on macOS. Darwin's default SysV backend fails with EINVAL once a
17+
# process holds locks on more than `kern.sysv.semume` (=10) semaphore sets
18+
# concurrently, which breaks any workload opening multiple DB environments in
19+
# one process (e.g. the storage-lmdb test suite).
20+
#
21+
# MDB_USE_ROBUST must be 0 because Darwin does not implement robust mutexes
22+
# (no PTHREAD_MUTEX_ROBUST); the cost is that a process crash while holding an
23+
# env lock can leave other processes deadlocked on that environment.
24+
# These flags are only applied when compiling FOR apple targets, so Linux/CI
25+
# builds keep upstream defaults (robust glibc pthread mutexes).
26+
[env]
27+
CFLAGS_aarch64-apple-darwin = "-DMDB_USE_POSIX_MUTEX=1 -DMDB_USE_ROBUST=0"
28+
CFLAGS_x86_64-apple-darwin = "-DMDB_USE_POSIX_MUTEX=1 -DMDB_USE_ROBUST=0"

0 commit comments

Comments
 (0)