Open genixpro opened 9 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)
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;
/**
@param callback */ module.exports.match = function (regex, str, callback) { var error = null; var match = null; if (!regex) { callback(error, match); return; }
var timeoutID = null;
globalWorker = new Worker(matchWorker); globalWorker.onmessage = function (evt) { // When the worker says its loaded start a timer. if (evt.data == "onload") { timeoutID = setTimeout(function () { globalWorker.terminate(); callback("timeout", match); }, 250); } else { match = evt.data.match; error = evt.data.error; clearTimeout(timeoutID); globalWorker.terminate(); callback(error, match); } }; globalWorker.postMessage({regex: regex, str: str}); };
function matchWorker () { var self = this; this.onmessage = function (evt) { "use strict";
}