busboy
busboy copied to clipboard
Accumulating files in memory
Running below code, with evey request, the app memory usage ( RSS ) increases until server runs out of memory. Why the buffers are not garbage collected after response is sent ?
import http from 'http'
import busboy from 'busboy'
http.createServer((req, res) => {
if (req.method === 'POST') {
const bb = busboy({ headers: req.headers });
bb.on('file', (name, file, info) => {
const chunks = [];
file.on('data', (data) => {
chunks.push(data);
})
file.on('end', () => {
console.log(info, Buffer.concat(chunks));
})
})
bb.on('close', () => {
res.writeHead(200, { Connection: 'close' });
res.end("Data Received")
});
req.pipe(bb);
}
}).listen(3000, () => {
console.log("Listening for requests")
})