https://bugs.openldap.org/show_bug.cgi?id=10529
Issue ID: 10529 Summary: assertion failure Product: LMDB Version: 1.0.0 Hardware: x86_64 OS: Linux Status: UNCONFIRMED Keywords: needs_review Severity: normal Priority: --- Component: liblmdb Assignee: bugs@openldap.org Reporter: christopher@gmerlin.de Target Milestone: ---
When testing the OCaml bindings with lmdb 1.0 I encountered this assertion failure: at src/mdb.c:7588: Assertion 'root > 1' failed in mdb_page_search()")
It was triggered by: - start transaction - add new key-value - commit transaction - rollback transaction - start read only transaction - try to get any key -> assertion failure
On another note I notice that this fails with MDB_CANT_ROLLBACK: - start transaction - commit ¡EMPTY! transaction - rollback transaction -> MDB_CANT_ROLLBACK
Of course this is a nonsensical transaction. But nevertheless maybe this case should be mentioned in the documentation, too.
https://bugs.openldap.org/show_bug.cgi?id=10529
--- Comment #1 from Howard Chu hyc@openldap.org --- (In reply to christopher@gmerlin.de from comment #0)
When testing the OCaml bindings with lmdb 1.0 I encountered this assertion failure: at src/mdb.c:7588: Assertion 'root > 1' failed in mdb_page_search()")
It was triggered by:
- start transaction
- add new key-value
- commit transaction
- rollback transaction
- start read only transaction
- try to get any key -> assertion failure
Will look into this later.
On another note I notice that this fails with MDB_CANT_ROLLBACK:
- start transaction
- commit ¡EMPTY! transaction
Committing an empty transaction is a no-op. The txnID doesn't advance.
- rollback transaction -> MDB_CANT_ROLLBACK
There is nothing to roll back in that case.
Of course this is a nonsensical transaction. But nevertheless maybe this case should be mentioned in the documentation, too.
https://bugs.openldap.org/show_bug.cgi?id=10529
Quanah Gibson-Mount quanah@openldap.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Keywords|needs_review | Target Milestone|--- |1.0.1
https://bugs.openldap.org/show_bug.cgi?id=10529
--- Comment #2 from Howard Chu hyc@openldap.org --- (In reply to christopher@gmerlin.de from comment #0)
When testing the OCaml bindings with lmdb 1.0 I encountered this assertion failure: at src/mdb.c:7588: Assertion 'root > 1' failed in mdb_page_search()")
It was triggered by:
- start transaction
- add new key-value
- commit transaction
- rollback transaction
- start read only transaction
- try to get any key -> assertion failure
Unable to reproduce. On a freshly created DB, where these steps are the very first transaction in the environment, the rollback yields MDB_CANT_ROLLBACK because the txnid is 1 and it can't rollback to txnid 0 (which is not a valid txnid).
On a freshly created DB, where other data was added in txnid 1, and these steps are performed using txnid 2, the rollback succeeds and the subsequent readonly txn works fine.
Please provide the actual code to reproduce your issue.
https://bugs.openldap.org/show_bug.cgi?id=10529
--- Comment #3 from christopher@gmerlin.de christopher@gmerlin.de --- Created attachment 1177 --> https://bugs.openldap.org/attachment.cgi?id=1177&action=edit Reproduce failure
https://bugs.openldap.org/show_bug.cgi?id=10529
--- Comment #4 from christopher@gmerlin.de christopher@gmerlin.de --- I added a c program to reproduce the failure. Originally I hit this failure when running tests on the ocaml bindings.
The backtrace looks like this:
Got <blub> mdb.c:7588: Assertion 'root > 1' failed in mdb_page_search()
Program received signal SIGABRT, Aborted. 0x00007ffff7e4995c in ?? () from /lib/x86_64-linux-gnu/libc.so.6 (gdb) bt #0 0x00007ffff7e4995c in ?? () from /lib/x86_64-linux-gnu/libc.so.6 #1 0x00007ffff7df4cc2 in raise () from /lib/x86_64-linux-gnu/libc.so.6 #2 0x00007ffff7ddd4ac in abort () from /lib/x86_64-linux-gnu/libc.so.6 #3 0x000055555555671d in mdb_assert_fail (env=0x5555555792a0, expr_txt=0x55555557490d "root > 1", func=0x555555574b90 <__func__.13> "mdb_page_search", file=0x5555555747d4 "mdb.c", line=7588) at mdb.c:1995 #4 0x00005555555617d7 in mdb_page_search (mc=0x7fffffffdc90, key=0x5555555794b0, flags=0) at mdb.c:7588 #5 0x0000555555561664 in mdb_page_search (mc=0x7fffffffe0d0, key=0x0, flags=2) at mdb.c:7553 #6 0x0000555555568003 in mdb_cursor_init (mc=0x7fffffffe0d0, txn=0x55555557db00, dbi=2, mx=0x7fffffffded0) at mdb.c:9662 #7 0x000055555556205a in mdb_get (txn=0x55555557db00, dbi=2, key=0x7fffffffe290, data=0x7fffffffe280) at mdb.c:7763 #8 0x0000555555573af2 in main () at test.c:87
I hope you can reproduce this now.
https://bugs.openldap.org/show_bug.cgi?id=10529
Howard Chu hyc@openldap.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |TEST
--- Comment #5 from Howard Chu hyc@openldap.org --- Fixed in 8e58bc1c6070aafa800ade8db3c8c006c1f5025c
https://bugs.openldap.org/show_bug.cgi?id=10529
--- Comment #6 from christopher@gmerlin.de christopher@gmerlin.de --- Created attachment 1179 --> https://bugs.openldap.org/attachment.cgi?id=1179&action=edit Expanded test program
https://bugs.openldap.org/show_bug.cgi?id=10529
Howard Chu hyc@openldap.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Attachment #1177|0 |1 is obsolete| |
--- Comment #7 from Howard Chu hyc@openldap.org --- Created attachment 1180 --> https://bugs.openldap.org/attachment.cgi?id=1180&action=edit Proper test program
For future reference:
The use of err() in your program is invalid, since it reports on errno and liblmdb doesn't touch errno, it returns error codes as its function return value. Only libc sets errno.
You should simply copy the model of the existing LMDB test programs, like this one does.
Your later program is still invalid since it uses strerror() which is only valid for libc errno values. It should be using mdb_strerror(). All of this is already plainly stated in the LMDB documentation.
https://bugs.openldap.org/show_bug.cgi?id=10529
--- Comment #8 from christopher@gmerlin.de christopher@gmerlin.de --- You are right, mdb_strerror() would have been more correct. But in this case it makes no difference.
I tested with again with this program against commit 6c1fc84aa979e00f5e505409138a49ceed69ac4f.
as probably expected mdb_get() after the rollback fails with 22(Invalid argument) instead of assertion failure because the dbi handle got invalidated. In my opinion this still es unexpected behaviour because the rollback has the side-effect of invalidating a dbi handle that was opened in another previous transaction.
Trying opening the dbi again fails with the old assertion failure:
Got <blub> on line 56 test: mdb_get(txn, dbi, &k, &v) on line 83 failed with 22 (Invalid argument) Got <(null)> on line 84 openldap-mdb.master3/libraries/liblmdb/mdb.c:7615: Assertion 'root > 1' failed in mdb_page_search()
Program received signal SIGABRT, Aborted. 0x00007ffff7e4995c in ?? () from /lib/x86_64-linux-gnu/libc.so.6 (gdb) bt #0 0x00007ffff7e4995c in ?? () from /lib/x86_64-linux-gnu/libc.so.6 #1 0x00007ffff7df4cc2 in raise () from /lib/x86_64-linux-gnu/libc.so.6 #2 0x00007ffff7ddd4ac in abort () from /lib/x86_64-linux-gnu/libc.so.6 #3 0x000055555555670d in mdb_assert_fail (env=0x55555557a2a0, expr_txt=0x55555557593d "root > 1", func=0x555555575bc0 <__func__.13> "mdb_page_search", file=0x5555555757d8 "openldap-mdb.master3/libraries/liblmdb/mdb.c", line=7615) at openldap-mdb.master3/libraries/liblmdb/mdb.c:1997 #4 0x0000555555561850 in mdb_page_search (mc=0x7fffffffdfd0, key=0x7fffffffe170, flags=0) at openldap-mdb.master3/libraries/liblmdb/mdb.c:7615 #5 0x00005555555632f8 in mdb_cursor_set (mc=0x7fffffffdfd0, key=0x7fffffffe170, data=0x7fffffffe160, op=MDB_SET, exactp=0x7fffffffdf9c) at openldap-mdb.master3/libraries/liblmdb/mdb.c:8149 #6 0x0000555555570b3b in mdb_dbi_open (txn=0x55555557b710, name=0x555555575dc2 "double txn_abort", flags=262152, dbi=0x7fffffffe21c) at openldap-mdb.master3/libraries/liblmdb/mdb.c:12332 #7 0x0000555555573f0a in main () at test.c:91
https://bugs.openldap.org/show_bug.cgi?id=10529
--- Comment #9 from Howard Chu hyc@openldap.org --- OK, previous fix was incorrect. Fixed again in be118dc94e6fe6a020d79bb6c2fb7d3aa79277e1
https://bugs.openldap.org/show_bug.cgi?id=10529
--- Comment #10 from christopher@gmerlin.de christopher@gmerlin.de --- Perfect! Now the test suite of the ocaml bindings completely passes as well.
https://bugs.openldap.org/show_bug.cgi?id=10529
Quanah Gibson-Mount quanah@openldap.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Assignee|bugs@openldap.org |hyc@openldap.org
--- Comment #11 from Quanah Gibson-Mount quanah@openldap.org --- mdb.master3:
• 8e58bc1c by Howard Chu at 2026-07-29T14:01:47+01:00 ITS#10529 lmdb: invalidate DBIs in rollback
• be118dc9 by Howard Chu at 2026-07-29T18:10:31+01:00 ITS#10529 lmdb: additional fixes
mdb.RE/1.0:
• 476c0b76 by Howard Chu at 2026-07-29T14:03:44+01:00 ITS#10529 lmdb: invalidate DBIs in rollback
• bf1b579a by Howard Chu at 2026-07-29T18:10:56+01:00 ITS#10529 lmdb: additional fixes
https://bugs.openldap.org/show_bug.cgi?id=10529
Quanah Gibson-Mount quanah@openldap.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Resolution|TEST |FIXED Status|RESOLVED |VERIFIED