-
Notifications
You must be signed in to change notification settings - Fork 30k
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
doc: clarify options for single customization hooks thread #53006
Conversation
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.
Thanks for this!
doc/api/cli.md
Outdated
`module` may be any string accepted as an [`import` specifier][]. This option | ||
has no effect on worker threads. |
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.
To me this reads as “the loader won’t apply to worker threads,” but what I assume you mean is “you don’t need to pass this argument when spawning a worker thread, as it will inherit from the main thread.” I’m not sure we need this addition at all; the other addition in module.md
might be enough.
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.
indeed that was intended. What do you think about: "This option
has no effect on worker threads. Worker threads inherit the customization hooks chain configured on main thread."
I can also remove this addition. The idea for adding it here as well was to have all relevant entry points in the documentation covered. To make it clear so that the user expectation is correct.
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 updated the commit with the last proposal. Let me know what you think
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.
@GeoffreyBooth friendly ping, trying to move this one forward. Is the current version suitable for landing?
80c8692
to
2496644
Compare
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.
The more I read this, the more that I think it’s unnecessary. Now that we’ve fixed it so that registered hooks apply to all threads, I don’t think we need to call out that it does work as expected. Before the recent fix it would’ve been good to document this unexpected behavior, but we’ve fixed it.
resolution and loading behavior. Registering modules that export [hooks][] only | ||
has an effect on the main thread. All worker threads inherit the customization | ||
hooks chain of the main thread. See [Customization 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.
“only has an effect on the main thread” sounds like the hooks don’t apply to worker threads. I just wouldn’t add anything here. I think the default assumption is that customization hooks apply everywhere, and thanks to the recent PR, now they do.
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.
ok, removed the change in cli.md
now.
do you mean by that the whole PR is not needed? Because I think it sets expectentions for the user correct.ly. One might expect they create a |
There are probably lots of runtime flags that don’t apply to Alternatively, rather than documenting things, we could update the runtime behavior to help users avoid footguns. So if |
we tried that as part of #52706 and we decided to take that up in an own follow-up as it is with current implementation of workers and other implementation details not easy either way (error or success of these operations). As long as this is not solved this behaviour imo should be documented. EDIT link to the relevant part of t he discussion on #52706 |
@@ -1008,7 +1008,10 @@ changes: | |||
* `execArgv` {string\[]} List of node CLI options passed to the worker. | |||
V8 options (such as `--max-old-space-size`) and options that affect the | |||
process (such as `--title`) are not supported. If set, this is provided | |||
as [`process.execArgv`][] inside the worker. By default, options are | |||
as [`process.execArgv`][] inside the worker. `--experimental-loader` | |||
and `--import` with `module.register()` calls to contribute to the 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.
Is it --import
which has no effect or is it the module.register()
call?
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.
strictly from code point of view it is the module.register()
but in terms of expectations with worker execArgv
(that this refers to) it is the combination of the two that does not have effect.
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.
In that case I find it a bit misplaced here as I would assume only very few users of workers actually use customization hooks. One might argue that setting process.title
in an --import
script does also not work so text here could get long over time.
I would prefer to improve the documentation at module.register
(already done here) and in the Customization Hooks
section. The Customization Hooks
section has no example for workers.
Also the sample Communication with module customization hooks
does not mention how to setup this from a worker (if it is possible at all).
In the Hooks
section there I read The hooks thread may be terminated by the main thread at any time
- which doesn't seem correct.
Also the behavior in case loader thread hangs or dies is not described.
Usually one would expect that workers are isolated but via customization hooks all of them are bound to the loader thread and via this one to main thread.
But not sure if it is your intention to get that far in this PR.
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 think let’s just cut the addition to worker_threads.md
and focus on module.md
?
resolution and loading behavior. Registering modules that export [hooks][] only | ||
has an effect on the main thread. All worker threads inherit the customization | ||
hooks chain of the main thread. See [Customization 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.
resolution and loading behavior. Registering modules that export [hooks][] only | |
has an effect on the main thread. All worker threads inherit the customization | |
hooks chain of the main thread. See [Customization hooks][]. | |
resolution and loading behavior. These hooks are run in a new thread | |
spawned for this purpose. After registration, the hooks will apply to any | |
modules imported on the main thread or on any worker threads created | |
by application code. See [Customization hooks][]. |
I know that for the main thread, obviously the hooks don’t apply to any modules already imported before the hooks are registered, and then they do apply to modules imported after registration; is it the same for worker threads? So if I have code that creates a new worker thread, then registers hooks, and then code within the worker thread does import()
, will that last import()
be customized?
And what happens when you call register
from a worker thread? If it just silently does nothing, we should probably change that to have it throw an error. I think it should either work as intended (adding new hooks to the customization chains) from wherever it’s called, or it should error when called from places where it doesn’t do its job.
@@ -1008,7 +1008,10 @@ changes: | |||
* `execArgv` {string\[]} List of node CLI options passed to the worker. | |||
V8 options (such as `--max-old-space-size`) and options that affect the | |||
process (such as `--title`) are not supported. If set, this is provided | |||
as [`process.execArgv`][] inside the worker. By default, options are | |||
as [`process.execArgv`][] inside the worker. `--experimental-loader` | |||
and `--import` with `module.register()` calls to contribute to the 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.
I think let’s just cut the addition to worker_threads.md
and focus on module.md
?
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.
hi @mcollina , |
I think we should actually revert that change, or at least revert it in v22 until that follow-up PR is done. #53183. |
As in, you think that users should need to define the hooks that should apply to worker threads, rather than all threads inheriting the hooks registered for the overall process? While per-thread hooks may be useful in certain scenarios, consider the default use case of an application developer writing their app in TypeScript, where that app uses worker threads. They should be able to launch their app via |
I think that #52706 breaks (at least) Angular and Ava, and the PR skipped a few tests to pass CI. I'm not on board with that implementation. I think "reusing" a worker should be supported, but that PR was not ready to land. |
triggered by comment on #47747.
This PR adds clarification on single customization chain thread that were introduced with #52706
@nodejs/loaders