Skip to content

Instantly share code, notes, and snippets.

@silverwind

silverwind/memory-leak.js

Last active Aug 29, 2015
Embed
What would you like to do?
var http = require('http');
var streamifier = require('streamifier');
var Busboy = require('busboy');
var FormData = require('form-data');
var PORT = 6666;
var data = new Buffer(100 * 1024 * 1024);
http.createServer(function(req, res) {
var busboy = new Busboy({headers: req.headers});
busboy.on('file', function() {
console.log('uploaded:', mb(data.length),' - memory used:', mb(process.memoryUsage().rss));
setTimeout(upload, 1000);
});
req.pipe(busboy);
}).listen(PORT, '127.0.0.1', upload);
function upload() {
var form = new FormData();
form.append('file', streamifier.createReadStream(data), {
filename: 'upload',
contentType: 'application/octet-stream',
knownLength: data.length
});
form.submit('http://127.0.0.1:' + PORT);
}
function mb(val) {
return Math.round(val / (1024 * 1024)) + " MB";
}
@skomski

This comment has been minimized.

Copy link

@skomski skomski commented Aug 17, 2015

Should fix it, or?

busboy.on('file', function(fieldname, stream) {
    stream.resume();
    console.log('uploaded:', mb(data.length),' - memory used:', mb(process.memoryUsage().rss));
    setTimeout(upload, 1000);
  });
@silverwind

This comment has been minimized.

Copy link
Owner Author

@silverwind silverwind commented Aug 18, 2015

@skomsi: Good find, it seems to solve the leak. It's kind of obvious now that the data is lost in that unconsumed stream, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment