Skip to content

Instantly share code, notes, and snippets.

@silverwind
Last active August 29, 2015 14:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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
Copy link

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
Copy link
Author

@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