kriszyp / lmdb-js

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

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

Open timotejroiko opened 1 year ago

timotejroiko commented 1 year ago

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!

kriszyp commented 1 year ago

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?

timotejroiko commented 1 year ago

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

alexghr commented 7 months ago

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)