lmdb-js icon indicating copy to clipboard operation
lmdb-js copied to clipboard

segfault when path set to null or undefined (typescript demands path to exist)

Open timotejroiko opened this issue 1 year ago • 3 comments

Hello,

According to documentation, omitting the path parameter during db.open() should create a temporary database that automatically deletes itself. However Typescript erroneously claims that path is a required parameter and cannot be omitted.

Furthermore, any attempt to make path behave as if omitted by setting it to null or undefined causes a segfault.

Not a high priority issue, but we could improve QOL here by both updating the typings to mark path as optional as well as preventing null/undefined path from segfaulting and make it behave as if it were omitted.

Thanks!

timotejroiko avatar Jun 20 '23 16:06 timotejroiko

I can update the typings, but I can't reproduce any segfault when omitting the path (in fact the unit tests extensively use databases opened without a path so that can run on temp databases). Do you have any steps to reproduce this?

kriszyp avatar Jun 21 '23 04:06 kriszyp

Hey, thanks for the reply.

For me it happens on node 20.3.0 on windows when you explicitly set path to a falsey value, for example { path: "" } or { path: null } or { path: undefined }. It works correctly if explicitly omitted like this {}

Using lmdb v2.8.2

timotejroiko avatar Jun 21 '23 08:06 timotejroiko

Hey, just to add to this: I've been using 2.9.1 and the typescript declarations seems to be different between ES and CJS files. index.d.cts has path as a required key in RootDatabaseOptionsWithPath while index.d.ts lists path as optional. As a result ts-jest fails to compile tests that are using temporary lmdb databases (there's a bug in ts-jest where it prefers .d.cts files over .d.ts or .d.mts https://github.com/kulshekhar/ts-jest/issues/4221)

alexghr avatar Nov 22 '23 22:11 alexghr