kriszyp / lmdb-js

Simple, efficient, ultra-fast, scalable data store wrapper for LMDB
Other
505 stars 42 forks source link

Exception when calling .remove() during iteration. #41

Closed paul-go closed 3 years ago

paul-go commented 3 years ago

e.g.:

for (const entry of db.getRange({}))
{
    await db.remove(entry.key);
}

This appears to happen fairly consistently. The exception is resolved when specifying { snapshot: false } in the iteration options. If there is no intention to support this, I believe users would prefer an error to be generated at the time of input, rather than going up in flames somewhere down the line.

kriszyp commented 3 years ago

From my testing, it appears that the underlying issue is that LMDB returns an error, MDB_PROBLEM: Unexpected problem - txn should abort, when attempting to remove the last remaining entry while there is an open read transaction (the cursor iterator keeps a read transaction open). Does that sound consistent with what you are seeing? I will try to put together a simple low-level test case to demonstrate the issue for LMDB itself.

kriszyp commented 3 years ago

Filed https://bugs.openldap.org/show_bug.cgi?id=9524 for reference.

kriszyp commented 3 years ago

This should be addressed in v1.2.5.

paul-go commented 3 years ago

Thanks Kris. Great work by the way.

1N50MN14 commented 3 years ago

@kriszyp MDB_PROBLEM: Unexpected problem - txn should abort showed up in 1.5.3-pre for me, and disappeared after upgrading to 1.5.3, not sure whether because I restarted the process or because the latest release fixes it. Just wanted to point this out.