From 53aee0a851bf72b4349a6ee934ac737128519b40 Mon Sep 17 00:00:00 2001 From: pullicino Date: Thu, 22 Jun 2017 11:55:40 +0200 Subject: [PATCH] Fix memory leak when http request stream is interrupted. --- index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/index.js b/index.js index a7fb771..f0d5f9a 100644 --- a/index.js +++ b/index.js @@ -162,6 +162,14 @@ var vidStreamer = function (req, res) { stream = stream.pipe(new Throttle(settings.throttle)) } + res.on('close', function(){ + stream.close(); + }); + + res.on('finish', function(){ + stream.close(); + }); + stream.pipe(res); return true; };