-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
Closed
Labels
domainIssues and PRs related to the domain subsystem.Issues and PRs related to the domain subsystem.
Description
Version: v6.14.3 and v10.5.0
Express Version: 4.16.4
Platform:
Linux m-pc 4.13.0-41-generic # 46~16.04.1-Ubuntu SMP Thu May 3 10:06:43 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
Steps (Generating a simple Express app):
$ npm install express-generator -g$ express --view=pug myapp$ npm i- Removing unneeded dependencies to keep it as simple and free of external dependencies.
- Adding some
domainimplementations.
var domain = require('domain');
// Patching global promise in response to https://github.com/nodejs/node-v0.x-archive/issues/8648
class PatchedPromise extends Promise {
// ...
}
Promise = PatchedPromise;
// Adding the `__awaiter` method to support old nodejs versions
var __awaiter = function (thisArg, _arguments, P, generator) {
// ...
};
var express = require('express');
var app = express();
app.use(function(req, res, next) {
let activeDomain = domain.active ? domain.active : domain.create();
activeDomain.run(() => {
if (domain.active.trap) {
throw new Error('Context Leaked!');
}
domain.active.trap = {};
__awaiter(this, void 0, void 0, function* () {
try {
yield new Promise(() => {
throw new Error('test');
});
}
catch (err) {
next(err);
}
});
});
});
module.exports = app;$ npm start- Send a POST request to
/.
Expected:
Always return Error('test').
Actual:
Only first request returns Error('test') and all the comming requests return Error('Context Leaked!')
A link to a repo to reproduce:
https://github.com/m0uneer/domain-promise-problem
Metadata
Metadata
Assignees
Labels
domainIssues and PRs related to the domain subsystem.Issues and PRs related to the domain subsystem.