{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/node/issues/22360","repository_url":"https://api.github.com/repos/nodejs/node","labels_url":"https://api.github.com/repos/nodejs/node/issues/22360/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/node/issues/22360/comments","events_url":"https://api.github.com/repos/nodejs/node/issues/22360/events","html_url":"https://github.com/nodejs/node/issues/22360","id":351191725,"node_id":"MDU6SXNzdWUzNTExOTE3MjU=","number":22360,"title":"Async Hooks do not recognize execution contexts created when processing thenables","user":{"login":"medikoo","id":122434,"node_id":"MDQ6VXNlcjEyMjQzNA==","avatar_url":"https://avatars3.githubusercontent.com/u/122434?v=4","gravatar_id":"","url":"https://api.github.com/users/medikoo","html_url":"https://github.com/medikoo","followers_url":"https://api.github.com/users/medikoo/followers","following_url":"https://api.github.com/users/medikoo/following{/other_user}","gists_url":"https://api.github.com/users/medikoo/gists{/gist_id}","starred_url":"https://api.github.com/users/medikoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/medikoo/subscriptions","organizations_url":"https://api.github.com/users/medikoo/orgs","repos_url":"https://api.github.com/users/medikoo/repos","events_url":"https://api.github.com/users/medikoo/events{/privacy}","received_events_url":"https://api.github.com/users/medikoo/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":28,"created_at":"2018-08-16T12:51:15Z","updated_at":"2018-12-06T11:39:58Z","closed_at":"2018-11-19T16:11:45Z","author_association":"NONE","body":"`Promise.all` to observe input promises, invokes `promise.then` in next event loop, at least it's what stack traces show in both Node.js and Google Chrome.\r\n\r\nStill Async Hooks see it as same execution context, it can be seen by running following code:\r\n\r\n```javascript\r\nconst async_hooks = require('async_hooks');\r\n\r\nasync_hooks.createHook({ init() {} }).enable();\r\n\r\nPromise.all([\r\n  {\r\n    then() {\r\n      console.log(async_hooks.executionAsyncId(), async_hooks.triggerAsyncId(), 'thenable.then invoked by Promise.all');\r\n      console.trace('thenable.then invoked by Promise.all');\r\n    },\r\n  },\r\n]);\r\n\r\nconsole.log(async_hooks.executionAsyncId(), async_hooks.triggerAsyncId(), 'Main');\r\nconsole.trace('Main');\r\n```\r\n\r\nThe outcome is:\r\n\r\n```\r\n1 0 'Main'\r\nTrace: Main\r\n    at Object.<anonymous> (/Users/medikoo/Projects/maas/maas-backend/test.js:15:9)\r\n    at Module._compile (internal/modules/cjs/loader.js:689:30)\r\n    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)\r\n    at Module.load (internal/modules/cjs/loader.js:599:32)\r\n    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)\r\n    at Function.Module._load (internal/modules/cjs/loader.js:530:3)\r\n    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)\r\n    at startup (internal/bootstrap/node.js:266:19)\r\n    at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)\r\n1 0 'promise.then invoked by Promise.all'\r\nTrace: promise.then invoked by Promise.all\r\n    at Object.then (/Users/medikoo/Projects/maas/maas-backend/test.js:9:15)\r\n    at process._tickCallback (internal/process/next_tick.js:68:7)\r\n    at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)\r\n    at startup (internal/bootstrap/node.js:266:19)\r\n    at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)\r\n```\r\n\r\nI've stumbled on that when trying to configure long stack trace solution for Node.js, and was dealing with custom promise implementations.\r\n\r\nI believe that's not expected.\r\n\r\n* **Version**: v10.9.0 (observable also on v8)\r\n* **Platform**: macOs 10.13.6 (17G65)\r\n"},"comment":{"url":"https://api.github.com/repos/nodejs/node/issues/comments/444843577","html_url":"https://github.com/nodejs/node/issues/22360#issuecomment-444843577","issue_url":"https://api.github.com/repos/nodejs/node/issues/22360","id":444843577,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0NDg0MzU3Nw==","user":{"login":"netproteus","id":503942,"node_id":"MDQ6VXNlcjUwMzk0Mg==","avatar_url":"https://avatars1.githubusercontent.com/u/503942?v=4","gravatar_id":"","url":"https://api.github.com/users/netproteus","html_url":"https://github.com/netproteus","followers_url":"https://api.github.com/users/netproteus/followers","following_url":"https://api.github.com/users/netproteus/following{/other_user}","gists_url":"https://api.github.com/users/netproteus/gists{/gist_id}","starred_url":"https://api.github.com/users/netproteus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/netproteus/subscriptions","organizations_url":"https://api.github.com/users/netproteus/orgs","repos_url":"https://api.github.com/users/netproteus/repos","events_url":"https://api.github.com/users/netproteus/events{/privacy}","received_events_url":"https://api.github.com/users/netproteus/received_events","type":"User","site_admin":false},"created_at":"2018-12-06T11:39:58Z","updated_at":"2018-12-06T11:39:58Z","author_association":"NONE","body":"I've just spent the last 3 days trying to follow thenable chains 3 dependencies deep from the code in my actual application. (Objection => Knex => Tarn) Was absolutely miserable to try and find the problems, thus far have found 3 and still there are more somewhere. And I suspect yet more in other code paths. It's all very well to say this can be worked around with AsyncResource, but thenables are part of the Promises/A+ spec, and there is nothing to stop anyone implementing or changing the implementation of libraries we all depend on directly or indirectly. IMHO unless thenables can be tracked without code changes async_hooks are completely useless."}}
{"actor":{"display_login":"netproteus"}}