开发者

My javascript web workers are dying silently at random places. How can I debug this?

开发者 https://www.devze.com 2023-02-05 23:46 出处:网络
The web worker just stops, no errors or anything. The code is entirely deterministic, but it will die at different points in the code.

The web worker just stops, no errors or anything. The code is entirely deterministic, but it will die at different points in the code.

Edit: The problem was that I was not maintaining a reference to my workers, and so they seemed to die randomly when they were garbage开发者_开发知识库 collected.


The problem was that I was not maintaining a reference to my workers, and so they seemed to die randomly when they were garbage collected.


I found a similar situation in Firefox where my worker seemed to be silently failing after a random number of calls to postMessage. After more digging, I found the real problem. Apparently invocations of the worker in Firebug was the issue. Firebug was touching a service in Firefox's chrome JS (privileged code space) that was causing the worker to fail intermittently, you can see the patch for it here: https://bugzilla.mozilla.org/show_bug.cgi?id=651980

As long as you do everything in accordance with the worker spec you shouldn't see this problem. As for the fix to Firebug/Fx, it should arrive in Firefox 5 in late June. Hope this helps you!


Same here with a web worker silently failing in firefox but not in chrome. Was using arborjs.org Called like this:

buildVisualization = function() {
  var sys = arbor.ParticleSystem(200, 200, 0.9); // create the system with sensible repulsion/stiffness/friction 
  sys.parameters({gravity:true}); // use center-gravity to make the graph settle nicely (ymmv) 
  sys.renderer = Renderer("#viewport"); // our newly created renderer will have its .init() method called shortly by sys... 
}

Where arbor is the object using a webworker.

I added the window.sys = sys; line and it now works like a charm both in firefox and chrome.

buildVisualization = function() {
  var sys = arbor.ParticleSystem(200, 200, 0.9); // create the system with sensible repulsion/stiffness/friction
  window.sys = sys;
  sys.parameters({gravity:true}); // use center-gravity to make the graph settle nicely (ymmv)
  sys.renderer = Renderer("#viewport"); // our newly created renderer will have its .init() method called shortly by sys...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消