-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
async_hooks: add --allow-async-hooks flag #61030
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
base: main
Are you sure you want to change the base?
Conversation
Add a new `--allow-async-hooks` flag that must be passed to enable `async_hooks.createHook()`. This is a breaking change - createHook is now disabled by default. When createHook() is called without the flag, it throws ERR_ASYNC_HOOKS_CREATE_HOOK_DISABLED with a message indicating that the flag is required. This change affects all code using async_hooks.createHook(), including APM tools and debugging utilities. Users must now explicitly opt-in to this functionality. BREAKING CHANGE: async_hooks.createHook() now requires --allow-async-hooks
|
Review requested:
|
|
Opening up to discuss this. I think this is the best path forward as they are extremely problematic to execute without somebody knowing what they are doing. I'm not sure if we would eventually remove themm, but this is the next step. Given that most APMs are actually using |
|
I agree this is a problematic api, we should get rid of it in the future, so +1 |
|
I'm also +1 on this. |
| } | ||
| ``` | ||
|
|
||
| ### `--allow-async-hooks` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be --enable-async-hooks, right? (and elsewhere in this PR)
|
I think we should either get rid of internal use in domain first (see here) or at least document there that use of domain requires this command line option set. |
|
I think there is one more internal use: if I think this case should be handled to adapt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm +1 on this, but I think we should also have a runtime API to enable this. Most APM tools offer the possibility of requiring their module to instrument the user's application. Enabling it via a CLI will cause them to create a wrapper for the user's application or make it a requirement in the user's configuration.
Summary
Add a new
--allow-async-hooksflag that must be passed to enableasync_hooks.createHook(). This is a breaking change - createHook is now disabled by default.Changes
--allow-async-hooksCLI flag (disabled by default)async_hooks.createHook()now throwsERR_ASYNC_HOOKS_CREATE_HOOK_DISABLEDwhen called without the flagcreateHook()to include the flagBreaking Change
async_hooks.createHook()now requires the--allow-async-hooksflag to be passed when starting Node.js.Most APM tools should now use
AsyncLocalStorageinstead, which is not affected by this change.Migration
Add
--allow-async-hooksto your Node.js command line orNODE_OPTIONS: