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

Exec failing with internal error when piping large output #818

Closed
ealmansi opened this issue Jan 19, 2018 · 3 comments
Closed

Exec failing with internal error when piping large output #818

ealmansi opened this issue Jan 19, 2018 · 3 comments
Labels
fix Bug/defect, or a fix for such a problem

Comments

@ealmansi
Copy link

ealmansi commented Jan 19, 2018

Node version (or tell us if you're using electron or some other framework):

8

ShellJS version (the most recent version/Github branch you see the bug on):

0.8.0

Operating system:

Ubuntu 16.04.3

Description of the bug:

Piping medium to large amounts of output between two exec's causes the second one to fail with 'Error: exec: internal error'.

Example ShellJS command to reproduce the error:

var shell = require('shelljs')
shell.config.fatal = true
shell.exec('cat small.txt', { silent: true }).exec('wc -l', { silent: true }).to('few-lines.txt')
shell.exec('cat big.txt', { silent: true }).exec('wc -l', { silent: true }).to('many-lines.txt')

Here, small.txt is a small file (under 1kb), while big.txt is a 2MB file.
The first command executes perfectly well, while the second one fails with exec: internall error.
Without fatal = true, the second exec on the second command simply returns null and the command fails due to to not being a property of null. (Likely related: #724)

Note

I did some digging and it seems the problem is here:

https://github.com/shelljs/shelljs/blob/master/src/exec.js#L68

That call to execFileSync receives execArgs, which contains the serialized output from the first exec. So it's essentially calling a process with an argument which is over 2MB, which is breaking a limit on my OS. That call to execFileSync ends with an Error: spawnSync /usr/bin/node E2BIG being thrown by node.

@nfischer
Copy link
Member

Thanks for digging into this! Yeah, it makes sense that there's a limit on argument size. Did this reproduce on 0.7.x?

It seems like #807 was wrong, and we may be able to fix this by reverting.

nfischer added a commit that referenced this issue Jan 19, 2018
This reverts commit 64d5899.

Reason for revert: If stdin is large, then the param object can become
an extremely long string, exceeding the maximum OS size limit on
commandline parameters.

Original change's description:
> refactor(exec): remove paramsFile (#807)
>
> The `paramsFile` is obsolete now that we use `execFileSync()` for our
> internal implementation. Instead, we pass parameters to the child
> process directly as a single commandline parameter to reduce file I/O.
>
> Issue #782

Fixes #818
@nfischer nfischer added the fix Bug/defect, or a fix for such a problem label Jan 19, 2018
nfischer added a commit that referenced this issue Jan 20, 2018
This reverts commit 64d5899.

Reason for revert: If stdin is large, then the param object can become
an extremely long string, exceeding the maximum OS size limit on
commandline parameters.

Original change's description:
> refactor(exec): remove paramsFile (#807)
>
> The `paramsFile` is obsolete now that we use `execFileSync()` for our
> internal implementation. Instead, we pass parameters to the child
> process directly as a single commandline parameter to reduce file I/O.
>
> Issue #782

Fixes #818
@nfischer
Copy link
Member

I'll release this in 0.8.1 soon

@FatihEbibelot
Copy link

FatihEbibelot commented May 2, 2018

I'm getting the same error with node v6.11.1 and shelljs v0.8.1,

screen shot 2018-05-02 at 12 07 02 pm

Code is;

var shell = require('shelljs')
var executionCommand = "/home/ubuntu/Audiveris/bin/Audiveris -batch"
shell.exec(executionCommand, function(error, stdout, stderr) {
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug/defect, or a fix for such a problem
Projects
None yet
Development

No branches or pull requests

3 participants