geocar / mmap

node mmap implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sporadic mmap failure

kotsss opened this issue · comments

Hi,
My code sporadically crashes in:

#
# Fatal error in ../deps/v8/src/api.h, line 297
# CHECK(allow_empty_handle || that != __null) failed
#

==== Stack trace ============================================

Security context: 0x16fc80a06b71 #0#
    1: map(aka mmap_wrapper) [/root/.znpm_cache/mmap-2.0.1/index.js:18] (this=0x33e128f04119 #1#,size=2844,protection=1,flags=1,fd=15,offset=0x16fc80a04121 )
    2: arguments adaptor frame: 4->5
    3: get_mmap(aka get_mmap) [REDACTED] (this=0x16fc80a04121 ,path=0x2c985e7177f9 ,table=0x2c985e7b5ac9 )

The code loads a few files using the same mmap code with no problem before this point and it does exist (has a valid fd '15').

I've tried looking around for a possible cause for this and found this: nodejs/node-v0.x-archive#5864

I'm not very familiar with wrapped c++ code in node libs, does anyone have an idea of the cause or point me in the right direction?

Thanks,
Shachar W.

You can post your code if you want.

There's isn't much into my code, this function is the only usage of mmap, it's called about half-dozen times for different files on the module init stage, most of the time all the calls succeed, but once in a while it crashes on one of them (not necessarily the first) with the above callstack.

var mmap = require('mmap');
.....
function get_mmap(path, table)
{
    var file = path+'/'+table, buffer;
    try { buffer = mmap.map(0, mmap.PROT_READ, mmap.MAP_SHARED, file); }
    catch(e) { throw new Error('failed to open '+file+': '+e); }
    zerr.debug('loaded mmap '+file);
    return buffer;
}

I've published 2.0.2 which does the contortion everyone else seems to be doing. It still works with my tests, but if it doesn't work for you maybe you could make a change to run_test.js that uses global.gc() to trigger the bug?