-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
process: stub unsupported worker methods #25587
Conversation
function unavailable(name) { | ||
return function unavailableInWorker() { | ||
throw new ERR_WORKER_UNSUPPORTED_OPERATION(name); | ||
}; |
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.
Just a suggestion, but maybe add a disabled: true
property on the function, so that feature detection remains about as easy as it is right now?
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'll add that.
Follow up question. Isn't using isMainThread
the preferable way to detect if you're running in a worker though?
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
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.
Follow up question. Isn't using
isMainThread
the preferable way to detect if you're running in a worker though?
@cjihrig Yes, I’d say so.
Also, fyi, we may want to provide a way in our embedder API to create a Worker-like environment, i.e. with access to per-process data disabled or restricted like we do for Workers.
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.
@refack I stuck with unavailable()
just because it's a bit shorter and required fewer uses to be wrapped across multiple lines.
function unavailable(name) { | ||
return function unavailableInWorker() { | ||
throw new ERR_WORKER_UNSUPPORTED_OPERATION(name); | ||
}; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
lib/internal/bootstrap/node.js
Outdated
mainThreadSetup.setupChildProcessIpcChannel(); | ||
} else { | ||
process.channel = null; | ||
process.connected = false; |
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 am not sure if these values make sense in the context of workers...what if the process (and the main thread) was spawned with child_process
? Maybe we could just throw errors in getters for all these if they just do not make sense (or are too difficult to implement properly) for workers? As far as I can tell, if a user needs to be prepare for the cases where these properties are not available, they are probably just being prepared for the workers, and could use something like require('module').builtinModules.includes('worker_threads') && require('worker_threads').isMainThread
as guards instead. Throwing in the getters should also help with debugging issues like #25448 .
Is this semver major? If they didn't exist, could someone be null-checking the properties to see if they can be called? (I doubt anyone is, but...) |
@Fishrock123 Workers are still experimental so I think we’re good here |
CI: https://ci.nodejs.org/job/node-test-pull-request/20386/ I guess this is technically ready? |
There are some tests to fix here first. |
Oh, and I've also been thinking about if I really want to take the approach in this PR or not. |
886b04b
to
e5f10ec
Compare
Fixed the test issues. Green CI: https://ci.nodejs.org/job/node-test-pull-request/20600/ |
One last green CI: https://ci.nodejs.org/job/node-test-commit/25637/ |
Some process methods are not supported in workers. This commit adds stubs that throw more informative errors. PR-URL: #25587 Fixes: #25448 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
I’m adding the backport-requested-v11.x label, but other PRs probably just need to be backported first. |
Some process methods are not supported in workers. This commit adds stubs that throw more informative errors. PR-URL: #25587 Fixes: #25448 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Some
process
methods are not supported in workers. This commit adds stubs that throw more informative errors.Fixes: #25448
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes