Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Clean up in Child_process module #2463

Closed
wants to merge 1 commit into from

Conversation

AndreasMadsen
Copy link
Member

This is not really a patch but more like an issue

After have been hacking the child_process module for quite some time I have found some wired stuff.
I have tried to make sense of it in this patch. I think got most of it but I do not understand the magic errno variable there suddenly exist.

@AndreasMadsen
Copy link
Member Author

Without any intention #2038 is now affected by this bug/issue.

@@ -442,7 +442,7 @@ ChildProcess.prototype.spawn = function(options) {

this._internal.close();
this._internal = null;
throw errnoException(errno, 'spawn');
throw errnoException('EINVAL', 'spawn', 'Could not execute');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? Is errno unset or garbage?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bnoordhuis I have no problem with a errno var, but where is it created, really confusing :/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bnoordhuis Ah, okay, well I will restore that an make a comment.
Do we have a magic errno to: https://github.com/joyent/node/pull/2463/files#L0R51

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a magic errno to: https://github.com/joyent/node/pull/2463/files#L0R51

Yes. (I was actually just working on a small patch for v0.6 that updated that line of code when I saw your PR).

@bnoordhuis
Copy link
Member

Also, isn't this a dup of #2462?

@AndreasMadsen
Copy link
Member Author

@bnoordhuis yes it is, but I have already closed it. I messed up when creating that pull request.

@@ -497,6 +497,8 @@ ChildProcess.prototype.kill = function(sig) {
if (this._internal) {
this.killed = true;
var r = this._internal.kill(signal);
// TODO: raise error if r == -1?
if (r === -1) {
throw errnoException('ESRCH', 'kill', 'No such process');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a magic errno to this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. All bindings set errno on error. If they don't, it's probably a bug.

@AndreasMadsen
Copy link
Member Author

@bnoordhuis restored errno magic.

@AndreasMadsen
Copy link
Member Author

@bnoordhuis could we land this :)

@bnoordhuis
Copy link
Member

@AndreasMadsen: Is this patch targeted at v0.6 or master? If it's v0.6, can you revert the change that makes ChildProcess.prototype.kill throw on error?

Also, can you git rebase -i it into one, two or three logical commits?

@AndreasMadsen
Copy link
Member Author

@bnoordhuis This is targeted v0.6, I have splited this up in 4 logical commits and removed the .kill throw. I will make a patch about that in the when this has landed in v0.6 and merged with master.

@AndreasMadsen
Copy link
Member Author

@bnoordhuis ^

@@ -304,7 +306,6 @@ exports.execFile = function(file /* args, options, callback */) {
}

child.stdout.setEncoding(options.encoding);
child.stderr.setEncoding(options.encoding);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, by first look I thought this was just a line dublicate, this should not be deleted.

@AndreasMadsen
Copy link
Member Author

@bnoordhuis this is now fixed, tested and check - lets land this.

@AndreasMadsen
Copy link
Member Author

Note this has also been discussed at the IRC: http://piscisaureus.no.de/log/2012-01-13#20:06:04.073

// TODO make this more compatible with ErrnoException from src/node.cc
// Once all of Node is using this function the ErrnoException from
// src/node.cc should be removed.
var e = new Error(syscall + ' ' + errorno);
var message = errorno + ', ' + msg + (path ? ' \'' + path + '\'' : '');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turn the ternary operator into an if statement, this is hard to read.

In case of a write failure when using .fork an error would
be throw, however the errnoExecption was not used here
makeing it extreamly difficute to detect.
This is a bug since errno was used, but it was in the Error
message only.
@AndreasMadsen
Copy link
Member Author

@bnoordhuis Here you go, as minimal as it can ever be.

@piscisaureus
Copy link

Landed in ca6eded. Thanks @AndreasMadsen.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants