doc: unclear conditions under which Worker's 'messageerror' is emmited #36333
Copy link
Copy link
Closed
Labels
docIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.workerIssues and PRs related to the worker_threads module and Worker API.Issues and PRs related to the worker_threads module and Worker API.
Description
- Version: 14.15.1
- Platform: Linux 5.4.0-54-generic Proposal: Comment all the code #60-Ubuntu SMP Fri Nov 6 10:37:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
- Subsystem: worker_threads
Location
Section of the site where the content exists
Affected URL(s):
Description
Concise explanation of the problem
It is unclear from the documentation how one could cause/simulate messageerror to be emitted by the Worker. It would be useful to understand the conditions when it happens and also be able to simulate such situations when testing code. A concrete example when this would be helpful is in bree codebase, where test coverage has been skipped because there's no way to simulate this event.
- I would like to work on this issue and
submit a pull request.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
docIssues and PRs related to Node.js documentation.Issues and PRs related to Node.js documentation.workerIssues and PRs related to the worker_threads module and Worker API.Issues and PRs related to the worker_threads module and Worker API.
Activity
naz commentedon Dec 1, 2020
To be clear, I'm happy to update the docs and provide a PR. Just lacking enough knowledge on the internal c++ workings of workers.
Trott commentedon Dec 2, 2020
@nodejs/workers
jasnell commentedon Dec 7, 2020
pinging @addaleax (whom I believe has the most context / understanding of this part of the code)
benjamingr commentedon Dec 7, 2020
Look at parallel/test-crypto-key-objects-messageport.js and test/parallel/test-worker-message-port-transfer-filehandle.js
addaleax commentedon Dec 7, 2020
Yeah, that’s a fair point. Part of why this was was left appear unclear is that it is also unclear (to me) in the HTML spec when this event would be emitted in the browser implementations.
Currently, this event is emitted when there is an error occuring while instantiating the posted JS object on the receiving end, where there would otherwise be no way to communicate that situation.
The examples pointed to by @benjamingr are for situations in which Node.js API objects (not JS built-ins) are received in a
vm.Context, which is currently an environment in which Node.js APIs are not available. That is a known limitation for now, rather than something that is inherent to the way we build APIs. It’s also not a condition under whichmessageerrorwould be emitted on aWorker, onlyMessagePorts (because there’s no way to create aWorkerinside avm.Context).You could probably make some of the deserialization methods throw an exception in some way, and generate the event through that, for example by messing with the prototypes of Node.js API objects, but ultimately, I don’t think there’s any good way to generate these events through the public API currently.
I can’t think of any reason why deserializing a message should fail once it has been posted, except for limitations in Node.js’ builtins, so, for testing, I would currently recommend just to emit the events directly.
doc: clarify when messageerror is emitted
doc: clarify when messageerror is emitted
doc: clarify when messageerror is emitted
doc: clarify when messageerror is emitted