Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async_hooks.executionAsyncId and triggerAsyncId become 0 in async functions even with hooks installed #20404

Closed
NijiharaTsubasa opened this issue Apr 29, 2018 · 4 comments
Labels
async_hooks Issues and PRs related to the async hooks subsystem. duplicate Issues and PRs that are duplicates of other issues or PRs. promises Issues and PRs related to ECMAScript promises.

Comments

@NijiharaTsubasa
Copy link

NijiharaTsubasa commented Apr 29, 2018

  • Version: 10.0.0
  • Platform: Windows
  • Subsystem: async_hooks

My exist code breaks when I upgrade node to 10.0.0 (I implemented something similar to cls-hooked in my code, and it broke)

I have read the document, but it only said "Installing async hooks via async_hooks.createHook enables promise execution tracking.", no luck.

Here's some code that reproduces my problem:

const fs = require('fs-extra')
const async_hooks = require('async_hooks')

async_hooks.createHook({
  init(id, type, trigId) {
    fs.writeSync(1, 'start async ' + id + ' by ' + trigId +' \n')
  }
}).enable()


async function saveSomething() {
  await fs.writeFile('someFile.txt', 'blah')
}


async function initSomething() {
  console.log(`eid ${async_hooks.executionAsyncId()} tid ${async_hooks.triggerAsyncId()}`);
  await fs.readFile('someFile.txt')
  console.log(`eid ${async_hooks.executionAsyncId()} tid ${async_hooks.triggerAsyncId()}`); //both zero?!
  await saveSomething()
}

async function main() {
  await initSomething()
}

main()

node 10.0.0 outputs

start async 6 by 1
start async 7 by 1
eid 1 tid 0
start async 8 by 1
start async 9 by 1
start async 10 by 1
start async 11 by 1
start async 12 by 1
start async 13 by 9
start async 14 by 7
start async 15 by 10
start async 16 by 15
start async 17 by 16
eid 0 tid 0
start async 18 by 0
start async 19 by 0
start async 20 by 0
start async 21 by 0
start async 22 by 0
start async 23 by 0
start async 24 by 20
start async 25 by 19
start async 26 by 21
start async 27 by 26

node 9.4.0 (the old version I was using) ouputs:

start async 6 by 1
start async 7 by 1
eid 1 tid 0
start async 8 by 1
start async 9 by 1
start async 10 by 1
start async 11 by 7
start async 12 by 11
start async 13 by 6
start async 14 by 13
start async 15 by 9
start async 16 by 7
start async 17 by 10
start async 18 by 17
start async 19 by 18
eid 12 tid 11
start async 20 by 12
start async 21 by 12
start async 22 by 12
start async 23 by 12
start async 24 by 21
start async 25 by 24
start async 26 by 7
start async 27 by 26
start async 28 by 22
start async 29 by 21
start async 30 by 23
start async 31 by 30
@NijiharaTsubasa NijiharaTsubasa changed the title async_hooks.triggerAsyncId become 0 in async functions even with hooks installed async_hooks.executionAsyncId and triggerAsyncId become 0 in async functions even with hooks installed Apr 29, 2018
@addaleax addaleax added async_hooks Issues and PRs related to the async hooks subsystem. duplicate Issues and PRs that are duplicates of other issues or PRs. promises Issues and PRs related to ECMAScript promises. labels Apr 29, 2018
@addaleax
Copy link
Member

I think this is a duplicate of #20274 -- can you verify that?

@NijiharaTsubasa
Copy link
Author

@addaleax The notable difference is that I get 0 as CURRENT id (which broke my code) which didn't appear in that issue. I have no idea about how async_hooks works so I'm not sure if they are same problem.

@Qard
Copy link
Member

Qard commented May 1, 2018

Yes, I can verify this is a duplicate. The promise hooks components in V8 are no longer attributing resolves to their parent context properly. I'm not yet sure why.

@jasnell
Copy link
Member

jasnell commented Aug 12, 2018

Closing since this is a duplicate

@jasnell jasnell closed this as completed Aug 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
async_hooks Issues and PRs related to the async hooks subsystem. duplicate Issues and PRs that are duplicates of other issues or PRs. promises Issues and PRs related to ECMAScript promises.
Projects
None yet
Development

No branches or pull requests

4 participants