Segmentation Fault #124

Closed
tytyty opened this Issue Jul 3, 2013 · 5 comments

Comments

Projects
None yet
2 participants

tytyty commented Jul 3, 2013

// The following code produces a Segmentation Fault under Ubuntu and Windows 7 using node 0.11.3 and the latest node-fibers

// NOTE: commenting out the line marked below makes the issue disappear. Why?

var lotsOfFibers = function () {
    var fibers = new Array();
    var x = 0;

    var fiberOp = function () {
        while (true) {
            x++;
            Fiber.yield();
        }
    }

    for (var i = 0; i < 5000; ++i) {
        var currFiber = new Fiber(fiberOp);
        fibers.push(currFiber);
        currFiber.run(); //<<<<<<<<<<<<< COMMENT THIS LINE AND IT WORKS
    }
    console.log("x = " + x);

    fibers.forEach(function (fiber) {
        fiber.run();
    });

    console.log("x = " + x);

    fibers.forEach(function (fiber) {
        fiber.run();
    });

    console.log("x = " + x);
}
Owner

laverdet commented Jul 3, 2013

Could you confirm that this only happens on 32-bit builds, and not 64-bit?

tytyty commented Jul 3, 2013

Happens with a 64 bit build on Windows, and 32 bit on Ubuntu

tytyty commented Jul 3, 2013

FYI, it is a sporadic bug - I have gotten it to run (with fewer fibers), then run immediately again and have it hurl.

Owner

laverdet commented Jul 3, 2013

Does 08d66c9 "fix" it?

The problem you're running into is that too many fibers are being created and the system can't handle it one way or another. On 32-bit systems there's just not enough addressable memory for that many active stacks. On 64-bit Windows my system seems to crap its pants at around 3246 fibers for whatever reason (ERROR_COMMITMENT_LIMIT).

The patch above will at least detect this and throw a JS runtime error instead of segfaulting.

For what it's worth, on 64-bit Linux I managed to create 50k+ active fibers with 90mb of resident memory. It could have kept going for a while I'm sure, but I ctrl+c'd it because I was bored watching it.

tytyty commented Jul 3, 2013

Just for kicks... On my winx64, I just uninstalled node 0.11.3 and the latest fibers build, and installed the stable node and the npm of fibers.... I got 55k fibers using the code above with no issues.

@laverdet laverdet closed this Dec 17, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment