Open apalsapure opened 7 years ago
I don't understand why this happens, but here is an ad-hoc for this.
var errorPromise = function () {
var promise = new Promise((resolve, reject) => {
reject('str');
});
Promise.resolve(promise).then(function (obj) {
}).catch(function (err) {
//throw new Error(err);
return Promise.reject(err);
});
}
Actually, I think it's a async-listener problem, not continuation-local-storage. In this case, when throw an error in promise.catch method, it trigger 'unhandledRejection' instead of calling process._fatalException function. Missing calling for asyncCatcher
I'm using this module in my express app. As you suggested I have used it as a request context and stopped setting properties on
request
andresponse
. But I ran into a problem. When an error is thrown insidePromise
, active context(namespace) never exits. All the calls made after this; share same context.Following is a small code snippet which shows the issue.
Here when query string contains
test
, call to error promise is made. After this error when next call is made, the earlier context is still active.Following are the requests made and respective console output
For now before I call
namespace.run
, if the namespace is active, I explicitly callexit
on it. But this is not the right solution, as in parallel calls for few milliseconds the context is shared.Please let me know if I'm doing something wrong or propose a solution.
Thanks.