audreyt / node-webworker-threads

Lightweight Web Worker API implementation with native threads
https://npmjs.org/package/webworker-threads
Other
2.3k stars 149 forks source link

Segfault when using worker #51

Open genixpro opened 9 years ago

genixpro commented 9 years ago

Hello,

I'm using this module and I'm having an extreme level of difficulty trying to figure out why I'm getting segmentation faults. I'm trying to use this module to be able to execute a regular expression, but with a timeout. The regular expressions are provided by users and thus we need to protect against users who put in a malicious regex that takes a long time to execute.

No matter what I do and how I modify the code, it always seems to crash with exactly the same segmentation fault error:

PID 27647 received SIGSEGV for address: 0x7e68 /home/bradley/sensibill-api/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x10e5)[0x7f63535fd0e5] /lib/x86_64-linux-gnu/libpthread.so.0(+0x10340)[0x7f635a50c340] /usr/local/bin/node[0x6c16ef] /usr/local/bin/node(ZN2v85Utils16ReportApiFailureEPKcS2+0x12)[0x6c2302] /usr/local/bin/node(_ZN2v87Isolate7DisposeEv+0x25)[0x6d8ac5] /home/bradley/sensibill-api/node_modules/webworker-threads/build/Debug/WebWorkerThreads.node(+0x17377)[0x7f63531db377] /lib/x86_64-linux-gnu/libpthread.so.0(+0x8182)[0x7f635a504182] /lib/x86_64-linux-gnu/libc.so.6(clone+0x6d)[0x7f635a23147d]

The address is always EXACTLY the same - 0x7e68. It never changes no matter what I do to the code, its always segfaulting on that address.

Code looks like this:

var Threads = require('webworker-threads'), Worker = Threads.Worker;

var globalWorker = null;

/**

function matchWorker () { var self = this; this.onmessage = function (evt) { "use strict";

    var regex = new RegExp(evt.data.regex);
    var str = evt.data.str;
    var error = null;
    var match;

    // Let the callee know we're loaded
    self.postMessage("onload");

    match = regex.exec(str);

    self.postMessage({error: error, match: match});
    self.close();
}

}

bitifet commented 7 years ago

I just discovered a memory leak in my own code because I forgiven to call .terminate() method after using worker.

And just when I tried to fix it (adding 'worker.terminate()') I also got that segmentation fault error.

Off course, not terminating workers is not a good solution. But I hope it could help in pointing the actual problem...

I'm using Node v8.4.0 (for if it helps)