node.js - node request pipe hanging after a few hours -
i have endpoint in node app used download images
var images = { 'car': 'http://someurltoimage.jpg', 'boat': 'http://someurltoimage.jpg', 'train': 'http://someurltoimage.jpg' } app.get('/api/download/:id', function(req, res){ var id = req.params.id; res.setheader("content-disposition", "attachment; filename=image.jpg"); request.get(images[id]).pipe(res); });
now code works fine, after few hours of app running, endpoint hangs.
i monitoring memory usage of app, remains consistent, , other endpoints return json respond normal not if event loop somehow being blocked. there gotcha of kind missing when using request module pipe response? or there better solution achieve this?
i using express module.
you should add error listener on request because errors not passed in pipes. way, if request has error, close connection , you'll reason.
request .get(...) .on('error', function(err) { console.log(err); res.end(); }) .pipe(res)
Comments
Post a Comment