Passing data with circular references to a web worker may results in null data passed
Reported by
hecht.j...@gmail.com,
Mar 24 2018
|
|||||||
Issue description
Chrome Version : 65.0.3325.181
OS Version: 10.0
URLs (if applicable) :
Other browsers tested:
Add OK or FAIL after other browsers where you have tested this issue:
Safari:
Firefox: OK
IE/Edge: OK
What steps will reproduce the problem?
1. Build a javascript array containing 1000 objects, each object has a reference to the next object in the array. Sample code : var a=[]; for (var i=0; i<1000; i++){ a.push({}); if (i>0) a[i-1].next = a[i];
2. Post this array to a web worker
What is the expected result?
A copy of the array should be in the data of the message received by the web worker.
What happens instead of that?
The data in the message received by the web worker is null.
Please provide any additional information below. Attach a screenshot if
possible.
StackOverflow link: https://stackoverflow.com/questions/49405410/passing-data-with-circular-references-to-a-javascript-web-worker-on-chrome
Fiddle link:
https://jsfiddle.net/jvr4a50r/
UserAgentString: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
,
Mar 26 2018
hecht.joel@ Thanks for the feedback. Able to reproduce the issue on Windows 10 on the latest Canary 67.0.3379.0 and Stable 65.0.3325.181. Issue is not observed on Ubuntu 14.04 and Mac OS 10.12.6. On opening the give JSFiddle link, and on clicking on Test 100 button, can observe the output as 'ok 100' and on clicking Test 1000, can observe the output as 'ko : null data'. Attached is the screen shot for reference. This is a Non-Regression issue as this behavior is observed from M60 Chrome builds. Hence marking this as Untriaged for further updates from Dev. Thanks..
,
Mar 30 2018
,
Apr 6 2018
Increasing num of objects in the array from 1000 to 3000 gives me a stack overflow. "Uncaught RangeError: Maximum call stack size exceeded" Assigning to nhiroki@. Cc-ing jbroman@ is it may be related to serializations.
,
Apr 6 2018
,
Apr 6 2018
Re c#4: Yeah, this would be a messaging/serialization issue. jbroman@: Can you take a look at this?
,
Apr 6 2018
Circular references should absolutely work, but unfortunately we do need to traverse the object graph, and we do so using the call stack. If stack overflow occurs during serialization, we throw a RangeError, but during deserialization, we don't really have any other recourse. A messageerror event was added to the HTML spec which we could dispatch, but it's not apparent to me that it's the right thing to do. Regrettably a linked list is essentially the pathological case (but we haven't gotten many reports of this coming up in practice). From your Stack Overflow post, it seems to have found suitable workarounds. Fixing this in general would raise the depth limit (by using heap memory instead of the call stack), but would likely considerably complicate and slow our implementation, so I don't think it's likely to be prioritized soon, sorry. On that basis, I'm going to WontFix this, but thank you for the report nonetheless.
,
Apr 11 2018
@jbroman, how come Window.postMessage is able to transfer it with no problem? https://jsfiddle.net/jvr4a50r/14/ Isn't the data also serialized in this case? And if it is, can't the same algo be used for both Worker and Window?
,
Apr 11 2018
I would indeed expect window.postMessage and worker.postMessage and other MessagePort.postMessages to all behave the same. And for me both do seem to work... If I increase the size to too much, the sending site gets a RangeError which also seems pretty reasonable, but there does indeed seem to be a size somewhere where sending succeeds, but deserializing fails. Not sure if there is anything worth fixing here though/ |
|||||||
►
Sign in to add a comment |
|||||||
Comment 1 by ajha@chromium.org
, Mar 26 2018