canjs / can-zone

A context for tracking asynchronous activity in JavaScript applications.
https://v4.canjs.com/doc/can-zone.html
MIT License
92 stars 4 forks source link

Timeouts cleared within websocket events cause zone to hang #149

Open matthewp opened 7 years ago

matthewp commented 7 years ago

Consider this code:

var ws = new WebSocket(url);

var timeout = setTimeout(function(){
  // Testing if it worked.
}, 30000);

ws.onmessage = function(){
  clearTimeout(timeout);
};

This scenario happens with some socket.io logout libraries. The web socket message doesn't happen within a Zone, so the clearTimeout call doesn't cause the setTimeout's task to complete.

The fix is to make sure that websocket messages are wrapped within a Zone.

matthewp commented 7 years ago

https://github.com/canjs/can-zone/issues/108 is related.