Skip to content

Instantly share code, notes, and snippets.

@silverwind
Last active August 29, 2015 14:26
Show Gist options
  • Save silverwind/54b3829142f93d1127bc to your computer and use it in GitHub Desktop.
Save silverwind/54b3829142f93d1127bc to your computer and use it in GitHub Desktop.
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