Memory leak when the pipe response is disconnected
pfziom opened this issue · 1 comments
pfziom commented
When using the pipe method to stream the zip in the API response object, I am facing a memory leak if the download is disconnected or canceled. It works fine when the download is successfully completed.
Here is a code snippet of my usage. I am using loopback 3 for this.
authenticatedRoute.post('/downloadZip', function(req, res, next) {
try {
const s3Zip = require('s3-zip');
const filename = generateFilename();
const folder = getFolderName(req);
const fileArray = JSON.parse(req.body.files);
res.set('content-type', 'application/zip');
res.set('Content-Disposition', 'attachment; filename=' + filename);
s3Zip.archive({region: REGION, bucket: BUCKET, preserveFolderStructure: true, debug: true}, folder, fileArray)
.pipe(res);
} catch (e) {
throw e;
}
});
app.use(authenticatedRoute);``
relevant dependency versions in use:
"compression": "^1.7.4",
"jwt-decode": "^2.2.0",
"loopback": "^3.22.0",
"loopback-boot": "^2.6.5",
"loopback-component-explorer": "^6.2.0",
"loopback-ssl": "^1.0.4",
"s3-zip": "^3.1.0",
"strong-error-handler": "^3.0.0"
What I was expecting is that if the download from the browser is canceled, the memory used by the s3Zip.archive function would be cleaned up. But that is not happening.
orangewise commented
Are you able to fix this issue in s3-zip?