Skip to content

Commit

Permalink
Try to prevent more memory leaks by using .once and cleaning up event…
Browse files Browse the repository at this point in the history
… listeners on error and premature close.
  • Loading branch information
papandreou committed Apr 14, 2016
1 parent 7e57280 commit bb578dd
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/processImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ module.exports = function (options) {
if (filter.end) {
filter.end();
}
filter.removeAllListeners();
// Some of the filters seem to emit error more than once sometimes:
filter.on('error', function () {});
});
filters = null;
}
res.removeAllListeners();
}
}

Expand Down Expand Up @@ -152,19 +157,21 @@ module.exports = function (options) {
filters[i].on('etagFragment', function (etagFragment) {
etagFragments.push(etagFragment);
});
filters[i].on('error', handleError);
// Some of the filters appear to emit error more than once:
filters[i].once('error', handleError);
}

res.pipe(filters[0]);
filters[filters.length - 1].on('end', function () {
hasEnded = true;
cleanUp();
}).pipe(res);

res.on('error', function () {
res.once('error', function () {
res.unhijack();
next(500);
});
res.on('close', cleanUp);
res.once('close', cleanUp);
} else {
res.unhijack();
}
Expand Down

0 comments on commit bb578dd

Please sign in to comment.