We are streaming files from s3, its running well but sometime (randomly in few days) its gives error and node instance is getting down. our code is
s3Utils.headObject(assetId, function (err, metadata) {
if (err && err.code === 'NotFound') {
console.log("file not found on s3: ", assetId) ;
res.send({"success":false, "message":"file not found on s3: "+ assetId});
} else {
var download_file_name = assetId;
if(metadata.Metadata && metadata.Metadata.filename) {
download_file_name = metadata.Metadata.filename;
}
if(metadata.ContentLength) {
res.setHeader('Content-Length',metadata.ContentLength);
}
res.setHeader('Content-disposition', 'attachment; filename=' +download_file_name);
res.attachment(download_file_name);
var fileStream = s3Utils.getObjectAsReadStream(assetId);
fileStream.pipe(res);
}
});
we are getting below error in logs
events.js:154
throw er; // Unhandled 'error' event
^
Error: write after end
at writeAfterEnd (_stream_writable.js:166:12)
at PassThrough.Writable.write (_stream_writable.js:211:5)
at IncomingMessage.ondata (_stream_readable.js:536:20)
at emitOne (events.js:90:13)
at IncomingMessage.emit (events.js:182:7)
at IncomingMessage.Readable.read (_stream_readable.js:368:10)
at flow (_stream_readable.js:751:26)
at resume_ (_stream_readable.js:731:3)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)
Server is getting down after this error. Please suggest.
via A_J
No comments:
Post a Comment