Lightning.NET icon indicating copy to clipboard operation
Lightning.NET copied to clipboard

Is lmdb.dll compiled in Debug mode?

Open marcotod1410 opened this issue 7 months ago • 0 comments

In some Windows production environments, we observed that a specific Put operation makes the entire application crash in an uncontrollable way using the latest version of LightningDB and .NET 8. This is the code for reference:

using var env = new LightningEnvironment("path\\to\\data")
{
    MapSize = 100 * 1024 * 1024,
    MaxDatabases = 1
};
env.Open();

var byteKey = Encoding.UTF8.GetBytes("shard-StoragePubSub-all");
var byteValue = new byte[] { 10, 26, 10, 19, 10, 1, 55, 10, 2, 55, 51, 10, 2, 55, 53, 10, 2, 57, 50, 18, 2, 8, 2, 16, 11, 34, 1, 66 };

using (var tx = env.BeginTransaction())
using (var db = tx.OpenDatabase("ddata"))
{
    var putResult = tx.Put(db, byteKey, byteValue);  // crash!
    var result = tx.Commit();
}

Keep in mind that we were able to reproduce the crash only with a already created .mdb file taken from production. Let me know if you need it for testing.

While debugging, we discovered that the application crashes (exiting with code 3) on a failed assertion from lmdb.dll since the following message is printed on the console: mdb.c:2741: Assertion 'mp->mp_pgno != pgno' failed in mdb_page_touch() which is not expected in my opinion, since the lmdb.dll library should be built in Release mode and assertions should not be enabled.

I've managed to build the lmdb library myself in version 0.9.29 (using this script). With the rebuilt dll in Release mode, the application does not crash anymore and the Put operation returns a success status code. Conversely, I've built the library in Debug mode, by adding CFLAGS="-DDEBUG", and the assertion is effectively executed, leading to the application crash. Of course I'm not questioning the correctness of the operation since that assertion must mean something and for this reason I'll conduct an in-depth study of possible consequences over the fresh written database.

That being said, I've got a couple of questions:

  • Are native libraries bundled in Lightning.NET built in Debug mode purposefully?
  • If not so, would it make sense to also update the library versions, since the latest version is 0.9.33 and the bundled version is 3 years overdue?

marcotod1410 avatar Jul 04 '24 07:07 marcotod1410