Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Nodejs memory leaks on cancelling download with download manager

Nodejs memory leaks on cancelling download with download manager

Problem

I created a simple file downloader using Expressjs 3 and Nodejs 0.10

function download(req, res, filepath, filename){
    res.header('Content-Type', 'application/force-download');
    res.header('Content-Type', 'application/octet-stream');
    res.attachment(filename);
    res.download(filepath, filename);
}

Everything is OK, but when I test application with download managers (for example Internet Download Manager), when I abort or cancel download (before or during download), it throws a warning:

Trace
    at Socket.EventEmitter.addListener (events.js:160:15)
    at Socket.Readable.on (_stream_readable.js:653:33)
    at Socket.EventEmitter.once (events.js:179:8)
    at TCP.onread (net.js:512:26)

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use
emitter.setMaxListeners() to increase limit.

How can I remove listener after aborting file download?

Problem courtesy of: raminious

Solution

The problem is solved
Add setMaxListeners(0) after Expressjs definition:

var express = require('express');

//expressjs 2.x
//var app = module.exports = express.createServer();

//expressjs 3.x
var app = module.exports = express();

//ADD BELOW CODE
app.setMaxListeners(0);


Thanks to @robertklep

Solution courtesy of: raminious

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Nodejs memory leaks on cancelling download with download manager

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×