momentum icon indicating copy to clipboard operation
momentum copied to clipboard

Race condition

Open cscalfani opened this issue 2 years ago • 0 comments

It's possible for a race condition to occur where a clearTimeout (or clearInterval) is called BEFORE a fire message is handled by the browser thread.

The clearTimeout code in the browser thread deletes e.data.id (or intervalId as it's called there) from $momentum.idToCallback causing an exception in the fire handler.

To fix this, the fire handler should be changed to:

$momentum.worker.onmessage = function (e) {
    if (e.data.type === 'fire' && $momentum.idToCallback[e.data.id] != null) {
      $momentum.idToCallback[e.data.id]();
    }
  };

cscalfani avatar Jul 08 '22 14:07 cscalfani