Title: `enabledHooksExist()` doesn't work as intended · Issue #61019 · nodejs/node · GitHub
Open Graph Title: `enabledHooksExist()` doesn't work as intended · Issue #61019 · nodejs/node
X Title: `enabledHooksExist()` doesn't work as intended · Issue #61019 · nodejs/node
Description: I took a look at enabledHooksExist(), but as discussed in #59873 (comment) and #60913, it seems to not work as intended at the moment: Following the suggestion to use enabledHooksExist(), I spent quite some time on it and gave that a try...
Open Graph Description: I took a look at enabledHooksExist(), but as discussed in #59873 (comment) and #60913, it seems to not work as intended at the moment: Following the suggestion to use enabledHooksExist(), I spent q...
X Description: I took a look at enabledHooksExist(), but as discussed in #59873 (comment) and #60913, it seems to not work as intended at the moment: Following the suggestion to use enabledHooksExist(), I spent q...
Opengraph URL: https://github.com/nodejs/node/issues/61019
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`enabledHooksExist()` doesn't work as intended","articleBody":"I took a look at `enabledHooksExist()`, but as discussed in https://github.com/nodejs/node/pull/59873#issuecomment-3304866589 and https://github.com/nodejs/node/pull/60913, it seems to not work as intended at the moment:\r\n\r\n\u003e Following the suggestion to use enabledHooksExist(), I spent quite some time on it and gave that a try—but found that it consistently returned true, even when no async hooks were active. So, I reverted to using getHookArrays()[0].length \u003e 0, as it provides a more accurate reflection of the current hook state.\r\n\r\n---\r\n\r\n`enabledHooksExist()` checks `async_hook_fields[kCheck] \u003e 0`, but `kCheck` is intentionally set to `1` at Node.js startup, even when no user async hooks have been registered:\r\n\r\nFrom env.cc (L1763):\r\n\r\nhttps://github.com/nodejs/node/blob/e28656a6172c35d88a472e33894a11f0e9f98eee/src/env.cc#L1748-L1763\r\n\r\nThis means `enabledHooksExist()` **always** returns `true`, regardless of whether any `AsyncHook` instances have actually been created and enabled by user code.\r\n\r\n---\r\n\r\nThis behavior dates back to PR #15454 it seems, but even after going through that discussion, I don't really understand the reasoning behind it and the TODO that says we should revert this for LTS releases. I feel like `fields_[kCheck]` should instead be set to `0` during initialization.\r\n\r\nShould we just change that or add a new helper function that would essentially do `AsyncContextFrame.current() != null || getHookArrays()[0].length \u003e 0`?","author":{"url":"https://github.com/gurgunday","@type":"Person","name":"gurgunday"},"datePublished":"2025-12-10T21:46:47.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/61019/node/issues/61019"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:0134260e-6b13-b8c3-e73e-99612d75b1f9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8C04:39C3C2:C7C4159:CD819A0:6A4C4E3F |
| html-safe-nonce | 103d6b9ceaf855b5e79baa8e946637bd194a25293136982c8dc7a955f5a79489 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QzA0OjM5QzNDMjpDN0M0MTU5OkNEODE5QTA6NkE0QzRFM0YiLCJ2aXNpdG9yX2lkIjoiMTM2NzQ2NzU1MjQ2MDc4NzI2MyIsInJlZ2lvbl9lZGdlIjoic2VhIiwicmVnaW9uX3JlbmRlciI6InNlYSJ9 |
| visitor-hmac | e4eb2a63cd7c51baa51ba0b978e053b436057383617d610430d84fbc5e6a2fea |
| hovercard-subject-tag | issue:3716886106 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/61019/issue_layout |
| twitter:image | https://opengraph.githubassets.com/649ae0537d3d48fef3a3916bf8998c58ecbc8447bffb857aa8a02131aa76ae06/nodejs/node/issues/61019 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/649ae0537d3d48fef3a3916bf8998c58ecbc8447bffb857aa8a02131aa76ae06/nodejs/node/issues/61019 |
| og:image:alt | I took a look at enabledHooksExist(), but as discussed in #59873 (comment) and #60913, it seems to not work as intended at the moment: Following the suggestion to use enabledHooksExist(), I spent q... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gurgunday |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3d11bb817438277de2a940854450e83a7d32b6aeb5014e9e6b00a6423900251c |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 65d78903193f110d7a9d1f8587c6dc3cb911aae0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width