You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Platform: Arch Linux 4.20.4-arch1-1-ARCH deps: update openssl to 1.0.1j #1 SMP PREEMPT Wed Jan 23 00:12:22 UTC 2019 x86_64 GNU/Linux
Subsystem: worker_threads
I'm currently creating a worker_threads compatability library which seeks to replicate worker_threads behavior as accurately as possible using the child_process module. This has caused me to investigate a number of edge cases with the worker_threads module.
My own implementation question was something like this:
worker.postMessage(port1,[port1,port1]);
What should happen? Should postMessage throw or simply ignore the second entry in the transfer list? It turns out node.js does neither.
Example case:
constthreads=require('worker_threads');if(threads.isMainThread){constworker=newthreads.Worker(__filename);const{port1, port2}=newthreads.MessageChannel();port1.on('message',console.log);// Causes a segfault:worker.postMessage(port2,[port2,port2]);// Causes a fatal error:constbuf=newUint8Array(1);worker.postMessage(buf,[buf.buffer,buf.buffer]);}else{threads.parentPort.on('message',(port)=>{if(portinstanceofthreads.MessagePort)port.postMessage('hello');});}
It seems that a duplicate port in the transfer list causes a segfault (I'm sorry I don't currently have a debug build available to provide a stack trace).
Transferring a duplicate array buffer causes a fatal error (at least a bit more descriptive):
Throw a `DataCloneError` exception when encountering duplicate
`ArrayBuffer`s or `MessagePort`s in the transfer list.
Fixes: #25786
PR-URL: #25815
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
I'm currently creating a
worker_threads
compatability library which seeks to replicateworker_threads
behavior as accurately as possible using thechild_process
module. This has caused me to investigate a number of edge cases with theworker_threads
module.My own implementation question was something like this:
What should happen? Should
postMessage
throw or simply ignore the second entry in the transfer list? It turns out node.js does neither.Example case:
It seems that a duplicate port in the transfer list causes a segfault (I'm sorry I don't currently have a debug build available to provide a stack trace).
Transferring a duplicate array buffer causes a fatal error (at least a bit more descriptive):
Update:
After some more investigating, it looks like the browser throws a
DataCloneError
in both of these edge cases.Duplicate port:
Duplicate array buffer:
The text was updated successfully, but these errors were encountered: