You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
process.domain is undefined after using "await" in node7 #10724
Platform: 64-bit Windows 10, Darwin Kernel Version 16.3.0(macOS 10.12.2)
Subsystem:domain
I am trying to transform my code from Promise to await/async in node7, but I found it didn't work with domain.
Here is my code:
letd=require('domain').create();d.run(asyncfunction(){console.log(d===process.domain);// trueconsole.log(1,process.domain);// process.domain existsletresult=await(async()=>{returnnewPromise((resolve)=>{resolve('ok');});})();console.log(result,process.domain,d);/** * result: ok * process.domain: undefined * d: no change */});
As shown by the comments, process.domain is undefined after using await. However, If I remove await the result will be a Promise and process.domain is the same with d.
Is is a bug or something undocumented.
@sam-github
I've found the same situation when I am using Promise, that process.domain is undefined in callback. When I am using Promise, I hacked Promise.prototype.then and Promise.prototype.catch as the code blow:
Activity
sam-github commentedon Jan 10, 2017
Not doced in https://github.com/nodejs/node/blob/master/doc/topics/domain-postmortem.md, however, domains are deprecated in the docs, for reasons such as this.
They are known to not work with promises, though I'm having trouble finding a ref.
nodejs/node-v0.x-archive#8648 discusses some issues
vkurchatkin commentedon Jan 10, 2017
We can fix this once V8 5.5 lands
zkd8907 commentedon Jan 11, 2017
@sam-github
I've found the same situation when I am using
Promise, thatprocess.domainis undefined in callback. When I am usingPromise, I hackedPromise.prototype.thenandPromise.prototype.catchas the code blow:process.domainexists in callback after the hack by myself. However, there is no way to hack await/async.addaleax commentedon Apr 21, 2017
This would be fixed by #12489
domain: support promises
emilsedgh commentedon May 8, 2017
Thank you so much for fixing this.
Is it gonna be released with 7.11?
addaleax commentedon May 9, 2017
@emilsedgh Sorry, you’ll need to wait for 8.0.0 – older versions of V8 don’t have the necessary hooks for Node to handle this.
edit: but just so you know, we’ll be bringing out a 8.0.0 RC very shortly – please try that out!
emilsedgh commentedon May 9, 2017
Oh thank you for letting me know. Fingers crossed for 8.0!
I tried it out by building master and it works perfectly fine.
zkd8907 commentedon Jun 1, 2017
Thanks for fixing the issus. It works well at 8.0.0 now.
domain: support promises