-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug in timer initialisation steps: the id's of cleared but still live timers can be reused #10387
Comments
Well spotted! How about instead of removing the entry, we set its value to null? And then update all the call sites to account for that. This is similar to your second map idea I think, but seems easier to get right. cc @domenic |
It feels like whatwg/infra#396 might be related here, although I'm not sure it's exactly the same thing. How Chromium's code does it is it keeps a "next timer ID" variable. That seems relatively simple and still allows us to clear the map entries. It also reduces implementation-defined behavior. |
Ah okay, that's good info. That's also pretty much how Firefox does it. By the way, I spotted some Undefined Behaviour in that Chromium code (signed int overflow), which I've sent in a patch for. The Firefox code is also technically broken, because the value can overflow and use the ID 0, or reuse ID's. (The webIDL types should probably also be changed to unsigned long). |
Nice! Do you want to work on a spec PR to incorporate a good algorithm here? |
whatwg#10387 Previously, it had been possible for timer IDs to be reused after having been cleared by clearTimeout(), which caused problems when the Run Steps After a Timeout callback was eventually executed. The problem was fixed by setting the value of cleared timeouts in the map of active timers to null, which prevents the IDs from being reused until after the relevent algorithm steps have actually executed. It may have been better to make the timeouts directly cancellable somehow, instantly releasing their timer IDs, as that is much closer to how real real browsers implement clearTimeout(), and the difference is technically observable if you somehow manage to exhaust all the timeout IDs. However, I couldn't work out how to do it that way in the specification language.
Alright, I've had a bash at fixing the spec. |
What is the issue with the HTML Standard?
The timer initialisation steps have a bug related to how timers that have been cancelled are represented, and how new timer IDs can be generated that match cleared (but still existing) timers. This is best illustrated with an example, consider these things happening in order:
I can see two ways of attacking this problem:
The text was updated successfully, but these errors were encountered: