kriszyp / lmdb-js

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

Issue with existing a cursor after lmdb-store 1.1.8 #36

Closed kylebernhardy closed 3 years ago

kylebernhardy commented 3 years ago

Hi,

Since release 1.1.8 of lmdb-store the following code now causes an error when breaking out of a cursor when reading the results of a dbi, same error occurs for getRange & I suspect all iterators. Is there a more preferred way of exiting the cursor?

const fs = require('fs');
const path = require('path');
const lmdb = require('lmdb-store');

function createEnv(name){
    let environment_path = path.join(__dirname, 'data', name);
    try {
        fs.rmdirSync(environment_path, {recursive:true})
        fs.mkdirSync(environment_path);
    }catch(e){
        console.error(e);
    }
    let env_init = {
        "path": environment_path,
        "mapSize": 1024*1024,
        "maxReaders": 100
    };
    let env = lmdb.open(env_init);
    return env;
}

let env = createEnv('test');

let id_dbi = env.openDB('id', {
    create: true,
    dupSort: false,
    useVersions: false});

id_dbi.putSync(-100, {});
id_dbi.putSync(-999.6743, {});
id_dbi.putSync(-22.2, {});
id_dbi.putSync(0, {});
id_dbi.putSync(5, {});
id_dbi.putSync(19.45, {});
id_dbi.putSync(10000, {});
id_dbi.putSync(false, {});
id_dbi.putSync(true, {});
id_dbi.putSync('aaaa', {});
id_dbi.putSync('hello', {});
id_dbi.putSync('Hello', {});
id_dbi.putSync('world', {});
id_dbi.putSync('World', {});
id_dbi.putSync('Hello World', {});
id_dbi.putSync('A', {});

let x = 0;
for (let key of id_dbi.getKeys()){
    if(x++ > 5){
        break;
    }
    console.log(key);
}

on version 1.1.11 the error out put is:

false
true
-999.6743
-100
-22.2
0
C:\Users\kyleb\WebstormProjects\lmdb-test\index.js:58
    console.log(key);
            ^

TypeError: Iterator result undefined is not an object
    at Object.<anonymous> (C:\Users\kyleb\WebstormProjects\lmdb-test\index.js:58:13)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47
kriszyp commented 3 years ago

Published it in v1.1.12. Thanks for a great test case.

kylebernhardy commented 3 years ago

Thank you!

kylebernhardy commented 3 years ago

I updated to 1.1.12 & all tests pass on our end, thanks again.