Merge pull request #1083 from STRML/fixDomainLeak

Fix #1080 - domain memory leak.
This commit is contained in:
Raymond Feng 2015-02-09 17:37:42 -08:00
commit 9816999864
1 changed files with 6 additions and 6 deletions

View File

@ -46,12 +46,6 @@ function context(options) {
var enableHttpContext = options.enableHttpContext || false;
var ns = createContext(scope);
var currentDomain = process.domain = domain.create();
currentDomain.oldBind = currentDomain.bind;
currentDomain.bind = function(callback, context) {
return currentDomain.oldBind(ns.bind(callback, context), context);
};
// Return the middleware
return function contextHandler(req, res, next) {
if (req.loopbackContext) {
@ -62,6 +56,12 @@ function context(options) {
ns.bindEmitter(req);
ns.bindEmitter(res);
var currentDomain = domain.create();
currentDomain.oldBind = currentDomain.bind;
currentDomain.bind = function(callback, context) {
return currentDomain.oldBind(ns.bind(callback, context), context);
};
currentDomain.add(req);
currentDomain.add(res);