re1ro / grunt-bg-shell

Better shell commands for grunt
MIT License
50 stars 8 forks source link

add maxBuffer option #4

Closed sojournerc closed 11 years ago

sojournerc commented 11 years ago

running jetty using bgShell, occasionally the process is killed with the following error:

Error: stdout maxBuffer exceeded.

It would be optimal to have a maxBuffer option to avoid this issue.

re1ro commented 11 years ago

Hey! Could you please provide your grunt config to research the problem?

sojournerc commented 11 years ago

Exceeding the buffer only happens occasionally, generally depending on the logging level of jetty. Option bg: true for the watch command was blocking and jetty would not run, hence: "cmd: 'grunt watch &\n mvn -Pjetty-run'".

module.exports = function (grunt) {
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.loadNpmTasks('grunt-bg-shell');

    grunt.initConfig({
        watch: {
            css: {
                files: ['**/*.less', '**/*.css', '!target/**/*'],
                tasks: ['less']
            }
        },
        less: {
            development: {
                options: {
                    paths: ["css"],
                    dumpLineNumbers: 'mediaquery'
                },
                files: {
                    "target/compiled/css/main.css": "src/main/webapp/less/main.less"
                }
            }
        },
        // background shell utility
        bgShell: {
            runMavenWatchLess: {
                cmd: 'grunt watch &\n mvn -Pjetty-run'
            }
        }
    });
    // default task
    grunt.registerTask('default', ['develop']);
    grunt.registerTask('develop', ['target','less:development','bgShell:runMavenWatchLess']);

    grunt.registerTask('target', 'creates the target directory for less compile', function () {
        grunt.file.mkdir('target/compiled/css');
    });
};  
re1ro commented 11 years ago

You can solve the problem setting execOpts: maxBuffer to NaN or Infinity. You can see how it works in source code

davidmccabe commented 11 years ago

In what way is allocating memory forever a solution?

re1ro commented 11 years ago

If you want to run a command line tool with lots of output for a long time, for example.

davidmccabe commented 11 years ago

If you want to run a command line tool with a lot of output for a long time — you can't, because you'll run out of memory. While capturing the output of a subprocess can be useful, grunt is frequently used to run server processes, and so the default should be to not crash by discarding output periodically.

re1ro commented 11 years ago

That's just the way how child_process.exec works. You can see how it adds data chunks to buffer here. If you want to run your process forever I need to reimplement 'child_process.execFile' without keeping buffer

re1ro commented 10 years ago

@sojournerc @davidmccabe You can set execOpts.maxBuffer to false, 0, NaN or Infinite. But it won't buffer stdout and stderr for done callback

re1ro commented 10 years ago

Fixed in v2.2.0

davidmccabe commented 10 years ago

Thanks for fixing this!