Skip to content

Commit c5eae30

Browse files
fpavageaukeyurkarnik
authored andcommitted
Cache the dynamic debug instances to avoid leaking them
This is due to debug-js/debug#678. Fixes #174
1 parent 25ee0c2 commit c5eae30

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/validateResourcePath.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var url = require('url');
44
var debug_ = require('debug');
5+
const debugs = {};
56
const DOUBLE_STAR_PLACEHOLDER = '@@@@';
67
const SUPPORTED_SINGLE_FORWARD_SLASH_PATTERN = "/";
78

@@ -14,7 +15,13 @@ module.exports = function (config, req, res, decodedToken, productOnly, logger,
1415
const proxy = res.proxy;
1516
let urlPath = req.reqUrl.path;
1617

17-
var debug = debug_('plugin:' + componentName);
18+
// Cache the dynamic debug instances, to avoid a memory leak due to a bug currently present in the debug package.
19+
// See https://github.com/visionmedia/debug/issues/678
20+
var debug = debugs[componentName];
21+
if (!debug) {
22+
debug = debug_('plugin:' + componentName);
23+
debugs[componentName] = debug;
24+
}
1825

1926
var parsedUrl = url.parse(urlPath);
2027
debug('product only: ' + productOnly);
@@ -91,4 +98,4 @@ module.exports = function (config, req, res, decodedToken, productOnly, logger,
9198
else
9299
return matchesProxyRules;
93100
});
94-
}
101+
}

0 commit comments

Comments
 (0)