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

"(node) warning: possible EventEmitter memory leak detected" when try to modify a stream #9

Closed
dudesl opened this issue Sep 14, 2015 · 1 comment

Comments

@dudesl
Copy link

dudesl commented Sep 14, 2015

I use gulp-foreach to modify the name of asset names in a set of css sheets by this way:

.pipe($.foreach(function(stream, file){
            var fileName = path.basename(file.path, '.css');

            var assetsManifest = JSON.parse(fs.readFileSync(dest.dist.manifest + "images-manifest.json", 'utf-8'));

            _.each(assetsManifest, function (n, key) {
                  // this line produce the memory leak warning
                  stream.pipe($.replace(key, n))
            })

            return stream
                .pipe($.minifyCss())
                .pipe($.size({
                    title: fileName + '.min.css size: '
                }))
                .pipe(gulp.dest(dest.dist.styles))
                .pipe($.gzip())
                .pipe($.size({
                    title: fileName + '.min.css.gz size: '
                }))
                .pipe(gulp.dest(dest.dist.styles));
        }))

This is the console log:

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at Readable.EventEmitter.addListener (events.js:160:15)
    at Readable.on (_stream_readable.js:689:33)
    at Readable.EventEmitter.once (events.js:185:8)
    at Readable.pipe (_stream_readable.js:474:9)
    at /home/.../gulpfile.js:283:23

There's a lot of npm modules whit this issue. This is probably a node.js bug.
More info
http://stackoverflow.com/a/16222062
nodejs/node-v0.x-archive#5108

If you have a workaround let us know. When I have some time, I will try to fix it and make a PR.

Greetings!

@mariusGundersen
Copy link
Owner

What is $.replace, and why are you piping into it without using the result? It looks like you are mutating the contents of the file objects in place, which is not a good idea (always assume that the stuff you are sending down the stream is immutable and being copied from one pipe to the next).

Instead of foreaching outside the stream.pipe, why not try to foreach inside the pipe(...)? That way you don't fork the stream multiple times. You could use gulp-map for that. For example:

.pipe($.foreach(function(stream, file){
    var fileName = path.basename(file.path, '.css');

    var assetsManifest = JSON.parse(fs.readFileSync(dest.dist.manifest + "images-manifest.json", 'utf-8'));

    return stream
        .pipe(map(function(file){
            _.each(assetManifest, function(n, key){
                file.contents.replace(key, n);
                return file;
            });
        }))
        .pipe($.minifyCss())
        .pipe($.size({
            title: fileName + '.min.css size: '
        }))
        .pipe(gulp.dest(dest.dist.styles))
        .pipe($.gzip())
        .pipe($.size({
            title: fileName + '.min.css.gz size: '
        }))
        .pipe(gulp.dest(dest.dist.styles));
}))

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

No branches or pull requests

2 participants