René's URL Explorer Experiment


Title: async_hooks.triggerAsyncId() don't return the expected value in context of the connection callback of net.Server · Issue #21078 · nodejs/node · GitHub

Open Graph Title: async_hooks.triggerAsyncId() don't return the expected value in context of the connection callback of net.Server · Issue #21078 · nodejs/node

X Title: async_hooks.triggerAsyncId() don't return the expected value in context of the connection callback of net.Server · Issue #21078 · nodejs/node

Description: Version: 8.x and 10.x Platform: all supported Subsystem: async_hooks.triggerAsyncId() is expected to return the async id of the connection in the onconnection callback of server. This was specifically declared in the example of the async...

Open Graph Description: Version: 8.x and 10.x Platform: all supported Subsystem: async_hooks.triggerAsyncId() is expected to return the async id of the connection in the onconnection callback of server. This was specifica...

X Description: Version: 8.x and 10.x Platform: all supported Subsystem: async_hooks.triggerAsyncId() is expected to return the async id of the connection in the onconnection callback of server. This was specifica...

Opengraph URL: https://github.com/nodejs/node/issues/21078

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"async_hooks.triggerAsyncId() don't return the expected value in context of the connection callback of net.Server","articleBody":"\u003c!--\r\nThank you for reporting an issue.\r\n\r\nThis issue tracker is for bugs and issues found within Node.js core.\r\nIf you require more general support please file an issue on our help\r\nrepo. https://github.com/nodejs/help\r\n\r\n\r\nPlease fill in as much of the template below as you're able.\r\n\r\nVersion: output of `node -v`\r\nPlatform: output of `uname -a` (UNIX), or version and 32 or 64-bit (Windows)\r\nSubsystem: if known, please specify affected core module name\r\n\r\nIf possible, please provide code that demonstrates the problem, keeping it as\r\nsimple and free of external dependencies as you are able.\r\n-->\r\n\r\n* **Version**: 8.x and 10.x\r\n* **Platform**: all supported\r\n* **Subsystem**:\r\n\r\n\u003c!-- Enter your issue details below this comment. -->\r\nasync_hooks.triggerAsyncId() is expected to return the async id of the connection in the `onconnection` callback of server. This was specifically declared in the example of the async_hooks documentation which can be found [here](https://nodejs.org/dist/latest-v10.x/docs/api/async_hooks.html#async_hooks_async_hooks_triggerasyncid). \r\n\r\nHowever, after testing the example using both node 10.3.0 and 8.11.2, I found the result was different. Below is the code and output of my test.\r\nmy code:\r\n```\r\nlet net = require('net');\r\nlet async_hooks = require('async_hooks');\r\nlet fs = require('fs');\r\n\r\nasync_hooks.createHook({\r\n  init(asyncId, type, triggerAsyncId) {\r\n  \tfs.writeSync(1, `init hook: ${type}, asyncID: ${asyncId}, triggerID: ${triggerAsyncId}\\n`);\r\n  },\r\n  before(asyncId) {\r\n    fs.writeSync(1, `before hook: asyncID: ${asyncId}\\n`);\r\n  },\r\n  after(asyncId) {\r\n    fs.writeSync(1, `after hook: asyncId: ${asyncId}\\n`);\r\n  },\r\n}).enable();\r\nconst server = net.createServer((conn) => {\r\n  // The resource that caused (or triggered) this callback to be called\r\n  // was that of the new connection. Thus the return value of triggerAsyncId()\r\n  // is the asyncId of \"conn\".\r\n  // fs.wriateSync(1, '-- conn callback, triggerAsyncId:', async_hooks.triggerAsyncId());\r\n  let tid = async_hooks.triggerAsyncId();\r\n  let eid = async_hooks.executionAsyncId();\r\n  fs.writeSync(1, `-- conn callback, triggerAsyncId: ${tid}, executionAsyncId: ${eid}\\n`);\r\n}).listen(8000, () => {\r\n  // Even though all callbacks passed to .listen() are wrapped in a nextTick()\r\n  // the callback itself exists because the call to the server's .listen()\r\n  // was made. So the return value would be the ID of the server.\r\n  let tid = async_hooks.triggerAsyncId();\r\n  let eid = async_hooks.executionAsyncId();\r\n  fs.writeSync(1, `-- listen callback, triggerAsyncId: ${tid}, executionAsyncId: ${eid}\\n`);\r\n});\r\n```\r\n\r\nif I connect the server with another terminal by `connect localhost 8000`, then the output is:\r\n```\r\ninit hook: TCPSERVERWRAP, asyncID: 5, triggerID: 1\r\ninit hook: TickObject, asyncID: 6, triggerID: 5\r\nbefore hook: asyncID: 6\r\n-- listen callback, triggerAsyncId: 5, executionAsyncId: 6\r\nafter hook: asyncId: 6\r\ninit hook: TCPWRAP, asyncID: 7, triggerID: 5\r\nbefore hook: asyncID: 5\r\n-- conn callback, triggerAsyncId: 1, executionAsyncId: 5\r\nafter hook: asyncId: 5\r\nbefore hook: asyncID: 7\r\ninit hook: TickObject, asyncID: 8, triggerID: 7\r\nafter hook: asyncId: 7\r\nbefore hook: asyncID: 8\r\ninit hook: TickObject, asyncID: 9, triggerID: 8\r\ninit hook: TickObject, asyncID: 10, triggerID: 8\r\nafter hook: asyncId: 8\r\nbefore hook: asyncID: 9\r\nafter hook: asyncId: 9\r\nbefore hook: asyncID: 10\r\nafter hook: asyncId: 10\r\nbefore hook: asyncID: 7\r\nafter hook: asyncId: 7\r\n\r\n```\r\n\r\nPlease note the line `-- conn callback, triggerAsyncId: 1, executionAsyncId: 5`. It means in the connection callback, the triggerAsyncId is 1 instead of 7 which is expected.\r\n\r\nI investigated the code, and found the root cause is:\r\nWhen the callback is made, it was made on the TCPWrap instance of the server, and the server's triggerId (1) and asyncId (5) were pushed into the stack, thus lead to this result. While It seems that this mechanism is ok most of the time for normal callbacks, but for this new connection callback, I think we should add some logic to pass the triggerId of the new connection (actually a new TCPWrap instance) to push into the stack. I made a change based on that and verified the result, it could work.\r\n\r\nSo, I doubt is the issue due to document obsoleted or the code should be changed?\r\nI'd like to make a PR if it is confirmed, thanks.","author":{"url":"https://github.com/tingshao","@type":"Person","name":"tingshao"},"datePublished":"2018-06-01T08:20:21Z","url":"https://github.com/nodejs/node/issues/21078"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:7a87d993-f7f3-9237-3511-2b2dc046b4d1
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8524:2B3418:345449:442A2A:6AED1DD9
html-safe-noncef0e6ec0e677ea41ce65666d713adcafc55ab9a2661f50f2c3199ed4954be5542
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NTI0OjJCMzQxODozNDU0NDk6NDQyQTJBOjZBRUQxREQ5IiwidmlzaXRvcl9pZCI6IjM3NTUwNzE4MjI1Nzk0NDExMTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac87b733499d266b181f82f6b220a522dd81ba2ca70378cdc773ba1b04a0c10eea
hovercard-subject-tagissue:328424186
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/21078/issue_layout
twitter:imagehttps://opengraph.githubassets.com/7a4ec0ecd124f4822fd8235e15552becd329c53273f7b9561c1571ced3fdb3e5/nodejs/node/issues/21078
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/7a4ec0ecd124f4822fd8235e15552becd329c53273f7b9561c1571ced3fdb3e5/nodejs/node/issues/21078
og:image:altVersion: 8.x and 10.x Platform: all supported Subsystem: async_hooks.triggerAsyncId() is expected to return the async id of the connection in the onconnection callback of server. This was specifica...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernametingshao
hostnamegithub.com
expected-hostnamegithub.com
Nonee3e0f7f63e50c6fe879198a93a0a023a648ecc0a5e9bc3b5e033ac57172237e6
turbo-cache-controlno-preview
go-importgithub.com/nodejs/node git https://github.com/nodejs/node.git
octolytics-dimension-user_id9950313
octolytics-dimension-user_loginnodejs
octolytics-dimension-repository_id27193779
octolytics-dimension-repository_nwonodejs/node
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id27193779
octolytics-dimension-repository_network_root_nwonodejs/node
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release707a24b346ac8a82878b9c084efaa38a997660cb
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/nodejs/node/issues/21078#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2F21078
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2F21078
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=nodejs%2Fnode
Reloadhttps://github.com/nodejs/node/issues/21078
Reloadhttps://github.com/nodejs/node/issues/21078
Reloadhttps://github.com/nodejs/node/issues/21078
nodejshttps://github.com/nodejs
nodehttps://github.com/nodejs/node
Codehttps://github.com/nodejs/node
Issues655 (655)https://github.com/nodejs/node/issues
Pull requests666 (666)https://github.com/nodejs/node/pulls
Actionshttps://github.com/nodejs/node/actions
Projectshttps://github.com/nodejs/node/projects
Security and qualityhttps://github.com/nodejs/node/security
Insightshttps://github.com/nodejs/node/pulse
https://github.com/nodejs/node
New issuehttps://github.com/login?return_to=https://github.com/nodejs/node/issues/21078
New issuehttps://github.com/login?return_to=https://github.com/nodejs/node/issues/21078
#64583https://github.com/nodejs/node/pull/64583
async_hooks.triggerAsyncId() don't return the expected value in context of the connection callback of net.Serverhttps://github.com/nodejs/node/issues/21078#top
#64583https://github.com/nodejs/node/pull/64583
async_hooksIssues and PRs related to the async hooks subsystem.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22async_hooks%22
https://github.com/tingshao
tingshaohttps://github.com/tingshao
on Jun 1, 2018https://github.com/nodejs/node/issues/21078#issue-328424186
herehttps://nodejs.org/dist/latest-v10.x/docs/api/async_hooks.html#async_hooks_async_hooks_triggerasyncid
https://github.com/apapirovski
apapirovskihttps://github.com/apapirovski
on Jun 5, 2018https://github.com/nodejs/node/issues/21078#issuecomment-394698019
apapirovskihttps://github.com/apapirovski
async_hooksIssues and PRs related to the async hooks subsystem.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22async_hooks%22
on Jun 5, 2018https://github.com/nodejs/node/issues/21078#event-1663617352
https://github.com/Jeff-Lewis
Jeff-Lewishttps://github.com/Jeff-Lewis
on Feb 10, 2019https://github.com/nodejs/node/issues/21078#issuecomment-462112743
cls-hookedhttps://github.com/Jeff-Lewis/cls-hooked
issuehttps://github.com/Jeff-Lewis/cls-hooked/issues/36
@tingshaohttps://github.com/tingshao
https://user-images.githubusercontent.com/676289/52531357-e1dafe00-2ce1-11e9-8154-fb87ce739c95.png
https://github.com/Jeff-Lewis
Jeff-Lewishttps://github.com/Jeff-Lewis
on Feb 14, 2019https://github.com/nodejs/node/issues/21078#issuecomment-463828342
@AndreasMadsenhttps://github.com/AndreasMadsen
@addaleaxhttps://github.com/addaleax
https://github.com/kibertoad
kibertoadhttps://github.com/kibertoad
on May 26, 2020https://github.com/nodejs/node/issues/21078#issuecomment-634126866
@AndreasMadsenhttps://github.com/AndreasMadsen
@addaleaxhttps://github.com/addaleax
https://github.com/addaleax
addaleaxhttps://github.com/addaleax
on May 26, 2020https://github.com/nodejs/node/issues/21078#issuecomment-634132285
@kibertoadhttps://github.com/kibertoad
@apapirovskihttps://github.com/apapirovski
https://github.com/apps/github-actions
github-actionshttps://github.com/apps/github-actions
on Jun 27, 2026https://github.com/nodejs/node/issues/21078#issuecomment-4820340701
GitHub Actionshttps://help.github.com/en/actions
github-actionshttps://github.com/apps/github-actions
staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22stale%22
on Jun 27, 2026https://github.com/nodejs/node/issues/21078#event-27286145084
https://github.com/soreavis
soreavishttps://github.com/soreavis
on Jul 18, 2026https://github.com/nodejs/node/issues/21078#issuecomment-5012639054
#64583https://github.com/nodejs/node/pull/64583
@addaleaxhttps://github.com/addaleax
github-actionshttps://github.com/apps/github-actions
staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22stale%22
on Jul 19, 2026https://github.com/nodejs/node/issues/21078#event-28170500572
nodejs-github-bothttps://github.com/nodejs-github-bot
completedhttps://github.com/nodejs/node/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#64583https://github.com/nodejs/node/pull/64583
on Aug 28, 2026https://github.com/nodejs/node/issues/21078#event-30179353872
nodejs-github-bothttps://github.com/nodejs-github-bot
on Aug 28, 2026https://github.com/nodejs/node/issues/21078#event-30179353988
doc: fix triggerAsyncId() comment in async_hooks examplehttps://github.com/nodejs/node/commit/beb4fca154ed8d692a8f98a5a7a18ba11aac58e8
beb4fcahttps://github.com/nodejs/node/commit/beb4fca154ed8d692a8f98a5a7a18ba11aac58e8
aduh95https://github.com/aduh95
on Aug 29, 2026https://github.com/nodejs/node/issues/21078#event-30208027696
doc: fix triggerAsyncId() comment in async_hooks examplehttps://github.com/nodejs/node/commit/fa32d219dc6a9574ada28b6ad38e9f309ac1ad10
fa32d21https://github.com/nodejs/node/commit/fa32d219dc6a9574ada28b6ad38e9f309ac1ad10
doc: fix triggerAsyncId() comment in async_hooks examplehttps://github.com/nodejs/node/commit/922d4c4c377e229224c1459c8bba54b6131576cf
922d4c4https://github.com/nodejs/node/commit/922d4c4c377e229224c1459c8bba54b6131576cf
doc: fix triggerAsyncId() comment in async_hooks examplehttps://github.com/nodejs/node/commit/6124cffc6389a9caf040d5540d43a29af71c50e5
6124cffhttps://github.com/nodejs/node/commit/6124cffc6389a9caf040d5540d43a29af71c50e5
doc: fix triggerAsyncId() comment in async_hooks examplehttps://github.com/nodejs/node/commit/397b58e113e3b510447616e0092aeb15806dd4ec
397b58ehttps://github.com/nodejs/node/commit/397b58e113e3b510447616e0092aeb15806dd4ec
Sign up for freehttps://github.com/signup?return_to=https://github.com/nodejs/node/issues/21078
Sign in to commenthttps://github.com/login?return_to=https://github.com/nodejs/node/issues/21078
async_hooksIssues and PRs related to the async hooks subsystem.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22async_hooks%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.