Merge pull request #1083 from STRML/fixDomainLeak
Fix #1080 - domain memory leak.
This commit is contained in:
commit
9816999864
|
@ -46,12 +46,6 @@ function context(options) {
|
||||||
var enableHttpContext = options.enableHttpContext || false;
|
var enableHttpContext = options.enableHttpContext || false;
|
||||||
var ns = createContext(scope);
|
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 the middleware
|
||||||
return function contextHandler(req, res, next) {
|
return function contextHandler(req, res, next) {
|
||||||
if (req.loopbackContext) {
|
if (req.loopbackContext) {
|
||||||
|
@ -62,6 +56,12 @@ function context(options) {
|
||||||
ns.bindEmitter(req);
|
ns.bindEmitter(req);
|
||||||
ns.bindEmitter(res);
|
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(req);
|
||||||
currentDomain.add(res);
|
currentDomain.add(res);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue