Skip to content
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

Remove codeFile parameter #791

Merged
merged 5 commits into from Oct 31, 2017
Merged

Remove codeFile parameter #791

merged 5 commits into from Oct 31, 2017

Conversation

nfischer
Copy link
Member

This parameter isn't needed, we can easily rely on exit code status for this.

Eliminating the parameter reduces file IO, code complexity, and removes a busy
loop.

Issue #782

This parameter isn't needed, we can easily rely on exit code status for this.

Eliminating the parameter reduces file IO, code complexity, and removes a busy
loop.

Issue #782
@nfischer nfischer added exec Issues specific to the shell.exec() API refactor labels Oct 20, 2017
@nfischer nfischer self-assigned this Oct 20, 2017
});
} catch (e) {
// child_process could not run the command.
process.exit(127);
Copy link
Contributor

Choose a reason for hiding this comment

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

process.exit is potentially a bad idea if there are still callbacks in the queue, or if there are async tasks running, because they will not finish. Of course, at this point, neither of these should be the case, but I still think setting process.exitCode is a safer way to do this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, below this, we are manually ending stdoutStream and stderrStream when c.stdout and c.stderr end. Why do they need to be ended manually?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ack on process.exitCode, sounds like it will be safer.

I'm not sure if we need to manually end the stream. This is legacy code. What would end the streams otherwise, though?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would need to test this to make sure, but just a normal pipe should work:

c.stdout.pipe(stdoutStream);
c.stderr.pipe(stderrStream);

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think we can do that. We need things as-they-are in order to:

  1. Send output to stdio in real-time
  2. Save that output in a file (for when exec-child.js finishes)

If we pipe the output, then we can't achieve bullet 2.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can just pipe twice:

c.stdout.pipe(fs.createWriteStream(stdoutFile));
c.stderr.pipe(fs.createWriteStream(stderrFile));
c.stdout.pipe(process.stdout);
c.stderr.pipe(process.stderr);

Copy link
Member Author

Choose a reason for hiding this comment

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

Nevermind, I was confused. You're right 👍

@nfischer
Copy link
Member Author

Comments are addressed, I'll look into the CI failures

@codecov-io
Copy link

codecov-io commented Oct 27, 2017

Codecov Report

Merging #791 into master will increase coverage by 0.3%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #791     +/-   ##
=========================================
+ Coverage    95.5%   95.81%   +0.3%     
=========================================
  Files          34       34             
  Lines        1269     1361     +92     
=========================================
+ Hits         1212     1304     +92     
  Misses         57       57
Impacted Files Coverage Δ
src/exec.js 97.89% <100%> (+0.52%) ⬆️
src/exec-child.js 100% <100%> (ø) ⬆️
src/common.js 98.79% <0%> (+0.46%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9e3f9ab...63b5e21. Read the comment docs.

@nfischer
Copy link
Member Author

@freitagbr this is ready for review (tests should pass, the last commit is just a comment)

@freitagbr
Copy link
Contributor

freitagbr commented Oct 27, 2017

For reference, I found a few commits related to the { end: false } option passed for the pipes:

The way we have it currently is basically identical to piping without { end: false }, so I'm not sure if the original issues will crop up again. Perhaps it was an issue with node itself.

// child_process could not run the command.
/* istanbul ignore next */
process.exitCode = 127;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If childProcess.exec throws, then c will be undefined, right? That means the code below this try/catch will fail.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think you're right. We should actually think of valid cases which might trigger this and document them. I think maxBuffer normally triggers this, but we're hitting the maxBuffer on the execFileSync() call in exec.js first.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the current code for childProcess.exec, I'm not sure it can throw synchronous exceptions. Not sure about past versions of node, however.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm you may be right.

I tried adding all sorts of broken/invalid cases and couldn't actually trigger this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just for the sake of verifying, I looked through the history of childProcess.exec and it hasn't changed much in 2 years, basically since v0.12. So, it is safe to remove the try/catch

@nfischer
Copy link
Member Author

The way we have it currently is basically identical to piping without { end: false }, so I'm not sure if the original issues will crop up again. Perhaps it was an issue with node itself.

Thanks for researching. Looking back, we used to pipe stdout & stderr into the same file (externally visible as shell.exec().output). I changed this a while back to separate the two streams (so we have .stdout and .stderr). Now that we have 2 readable streams piping into 2 writable streams, we can use default stream-closing behavior.

@nfischer
Copy link
Member Author

@freitagbr I think everything is resolved.

@freitagbr
Copy link
Contributor

LGTM, I restarted the Travis builds for good measure.

@nfischer
Copy link
Member Author

Travis had problems last night 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exec Issues specific to the shell.exec() API refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants