Repository navigation
fix: drop MDB_WRITEMAP to avoid LMDB freelist assertion crash - #3639
Conversation
The macOS (with lmdb) CI job crashed deterministically in action-expirevar.json and issue-1831.json with: mdb.c:3900: Assertion 'x <= dl[0].mid' failed in mdb_freelist_save() Reproduced with a minimal standalone LMDB program (no ModSecurity code involved): a get/del/put/commit cycle on the same key, interleaved with a read-only get and a delete-only commit, crashes LMDB's mdb_freelist_save() when the environment is opened with MDB_WRITEMAP. The failing assertion is in the mt_loose_pgs/dirty-list reconciliation loop, which only runs "if (txn->mt_flags & MDB_TXN_WRITEMAP)" - this is still present in LMDB's current upstream 1.0 branch, i.e. not something fixed by upgrading. Apple Silicon's 16KB page size makes it far easier to hit than Linux's 4KB pages, which is why only the macOS lmdb job failed while Linux (same code, older liblmdb) passed. Opening the environment without MDB_WRITEMAP avoids the buggy code path entirely; the same repro runs cleanly, and the full test suite now passes (previously 3 failures, all lmdb-collection related). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe LMDB environment now opens the shared collection database with ChangesLMDB open configuration
Priority: ➖ Normal Estimated code review effort: 1 (Trivial) | ~2 minutes Change: Bug fix 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The reported regression tests pass and the macOS crash is resolved.
Review effort: Lite
Findings: None
What changed in this PR
Removes LMDB write-map mode to prevent deterministic freelist assertion crashes on Apple Silicon macOS.
Changes:
- Opens LMDB with
MDB_NOSUBDIRonly. - Preserves existing LMDB persistence behavior.
| File | Description |
|---|---|
src/collection/backend/lmdb.cc |
Removes MDB_WRITEMAP from LMDB environment initialization. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Thank you, @fzipi! |



Summary
The
macOS (with lmdb)CI job fails deterministically ontest/test-cases/regression/action-expirevar.jsonandtest/test-cases/regression/issue-1831.jsonwith:This reproduces with a minimal standalone LMDB program with no ModSecurity code involved: a
get/del/put/commit cycle on a key, interleaved with a read-onlygetand a delete-only commit, crashesmdb_freelist_save()when the environment is opened withMDB_WRITEMAP.The failing assertion is in the
mt_loose_pgs/dirty-list reconciliation loop insidemdb_freelist_save(), which only executesif (txn->mt_flags & MDB_TXN_WRITEMAP). This guard is still present at the current tip of LMDB's ownmdb.RE/1.0branch, so it is not fixed by upgrading LMDB.Apple Silicon macOS uses a 16KB page size (
sysctl hw.pagesize), versus 4KB on the Linux CI runners. The Linuxwith lmdbjobs useliblmdb-dev0.9.24 from Ubuntu and pass; the macOS job installs whatever Homebrew'slmdbformula currently resolves to (1.0.2 at the time of this PR). The same C++ code path is exercised on both platforms; only the macOS job fails, consistently, across multiple runs and multiple unrelated commits onv3/master.Change
src/collection/backend/lmdb.cc:mdb_env_open()no longer passesMDB_WRITEMAP, onlyMDB_NOSUBDIR.Test plan
MDB_WRITEMAPis removed frommdb_env_open, using the same environment (LMDB 1.0.2 via Homebrew, arm64 macOS).v3/masterplus this one-line change locally with./configure --with-lmdb --enable-assertions=yesandmake.make check: 5043 total, 5025 pass, 18 skip, 0 fail (previously 3 failures, all in the two files above, both LMDB-collection related).action-expirevar.jsonandissue-1831.jsonindividually, all sub-tests pass.Summary by CodeRabbit