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

Memory leak #177

Open
vanilla38 opened this issue Jan 6, 2017 · 2 comments
Open

Memory leak #177

vanilla38 opened this issue Jan 6, 2017 · 2 comments

Comments

@vanilla38
Copy link

Hello, I noticed that memory wasnt freed after download is complete, here's my code:

`app.get('/dltorrent', function (req, res) {
var urlObj = url.parse(req.url, true),
query = urlObj.query;

if (query.magnet !== undefined && query.title !== undefined && query.magnet !== 'undefined' && query.title !== 'undefined') {
	var opts = {
		tmp: '/usr/share/nodejs/www/data',
		connections: 10,
		uploads: 0
	}
	
	var engine = torrentStream('magnet:?xt=urn:btih:' + query.magnet, opts);
	engine.on('ready', function() {
		engine.files.forEach(function(file) {
			if (file.name == query.title) {
				var stream = file.createReadStream();
					res.setHeader('Content-disposition', 'attachment; filename=' + query.title);
					res.setHeader('Content-type', mime.lookup(query.title));
					stream.pipe(res);
			}
		});
	});
} else {
	res.end('invalid dl parameters');
}

});`

@vanilla38
Copy link
Author

Okay, I noticed that these leaks were caused by:

swarm.add(addr) => torrent-stream index.js Line 702

Any idea on how to solve it ?

@dizel3d
Copy link

dizel3d commented Jan 14, 2017

The leak is reproduced on Linux, not on Windows.
I simplified the leak reproduction, see https://github.com/dizel3d/node-memory-leak-sample
I made 300 iterations and couldn't detect leaking objects using v8-profiler, comparing heap snapshots. It seems the leak has native code roots.

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