-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
child_process.exec TypeError: Cannot read property 'addListener' of undefined #1321
Comments
Confirmed. The test case hits the max process limit ( |
note: if you run this in the REPL both errors fire:
|
@bnoordhuis would this patch be acceptable for now? It's going to error anyways. diff --git a/lib/child_process.js b/lib/child_process.js
index a38de28..ae0912a 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -961,7 +961,7 @@ var spawn = exports.spawn = function(/*file, args, options*/) {
debug('spawn', opts.args, options);
- child.spawn({
+ const err = child.spawn({
file: opts.file,
args: opts.args,
cwd: options.cwd,
@@ -973,6 +973,8 @@ var spawn = exports.spawn = function(/*file, args, options*/) {
gid: options.gid
});
+ if (err < 0) throw errnoException(err, 'spawn');
+
return child;
}; Discussed this a bit on irc with @cjihrig and it seems like it's generally a wonky case. Output with that patch (Still throws the latter error also if you are in the repl because existing reasons.)
|
This appears to be roughly the same as nodejs/node-v0.x-archive#8504. I started looking at this a while back and opened nodejs/node-v0.x-archive#8779. It doesn't solve the problem, but prevents the accesses of the streams that are causing the crashes. The file descriptors aren't leaked in the strictest sense of the word - it just takes some time for them to be freed (sockets must close, etc.). So, running this in a tight loop will always cause this problem, unless some changes are made around the code block that @Fishrock123 linked to. EDIT: The code to link to is https://github.com/iojs/io.js/blob/f3e9da3e69393acb6f2cb90c4dc53ae5908ac9ef/lib/child_process.js#L1106-L1157 |
@Fishrock123 I think it should be an 'error' event. It's a run-time error. |
I agree it should be an event. Assuming it is emitted in the next tick, won't you still potentially run into the case where EDIT: After testing, I did still hit that case. Thoughts on combining these changes with nodejs/node-v0.x-archive#8779? EDIT2: |
Unless you are checking for either an error or that the object is actually proper right there, you'll still end up with an error since |
Was this issue fixed or is there a workaround? I hit it today. |
I encountered the same issue, I tried to solve it with raising the maxproc limit on Mac and it did solve the problem in my case. However considering the maxproc is hard coded to 2500 on regular Mac OSX, this issue would show up when you have more than 2500 processes to run at the same time. |
Closing as this seems to have been fixed by #3799 |
Here's a code sample that triggers the error condition:
If I do not wrap with try/catch it will crash after ~258 iterations on io.js v1.6.3 on OSX 10.10.2
Here is the stack trace:
It seems that if a callback is passed, the general async-ism is to call it with any errors. Therefore the following:
Should change to something like this:
And the error handler should also include a null check on
child.stdout
andchild.stderr
.Additionally, when I do wrap with try/catch, it looks like it is emitting a spawn error on line 1022 which is not handled, even when adding an error listener on the child. It appears to be emitted by the
ChildProcess
object on line 1042. Its stack trace is as follows:I know this is a contrived example, but I've hit this edge case before.
Please let me know if I can clarify anything here. The expected behavior is that the script keeps running, rather than crashing io.js with a stack trace.
The text was updated successfully, but these errors were encountered: