Skip to content
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

Remove a setTimeout's entry in the map of active timers after it runs #7377

Merged
merged 2 commits into from
Nov 30, 2021

Conversation

andreubotella
Copy link
Member

@andreubotella andreubotella commented Nov 29, 2021

It used to be unobservable whether a non-repeating timer that had already run its callback had an entry in the list of active timers or not, and so those entries were never removed from the list. However, calculation of the idle deadline, meaning that if a timer expires and is never cancelled, the deadline will be in the past.

This change avoids this case by removing non-repeating timers from the map of active timers after their callback runs.

Closes #7376.

(See WHATWG Working Mode: Changes for more details.)


/timers-and-user-prompts.html ( diff )

It used to be unobservable whether a non-repeating timer that had
already run its callback had an entry in the list of active timers or
not, and so those entries were never removed from the list. However,
calculation of the idle deadline, meaning that if a timer expires and is
never cancelled, the deadline will be in the past.

This change avoids this case by removing non-repeating timers from the
map of active timers after their callback runs.

Closes whatwg#7376.
@andreubotella
Copy link
Member Author

andreubotella commented Nov 29, 2021

Now that I think about it, if timerKey in "run steps after a timeout" is not a number, it would also have to be removed from the map after the wait. I'm assuming that's fine, concurrency-wise.

@annevk
Copy link
Member

annevk commented Nov 30, 2021

I think this works, but I also think the current setup is broken in other ways. It works for AbortSignal now, but if we wanted to add timeout support to AbortController so it could also be removed again, there's no way to do that currently. That would require handing the key back to the calling algorithm and checking if the key is still in the map before running completionSteps.

Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems good to me. Regarding @annevk's comment, it doesn't feel like the current setup is broken, but instead that we'd have to add more complications to it if we want to allow more complicated caller patterns in the future?

@domenic domenic merged commit e9ba78f into whatwg:main Nov 30, 2021
@andreubotella
Copy link
Member Author

This PR wasn't editorial, and I was planning on writing tests for it (and seeing if any browser engine bugs needed to be filed) tomorrow.

@andreubotella andreubotella deleted the remove-entry-in-timer-map branch November 30, 2021 22:15
@domenic
Copy link
Member

domenic commented Nov 30, 2021

Oh, I'm so sorry about that! I was thinking of it as a bugfix to bd63843, but I agree that probably this case wasn't covered in the tests for that commit, so it would have been better to wait.

@annevk
Copy link
Member

annevk commented Dec 1, 2021

@domenic yeah I guess that can work. I was thinking that might allow consolidation of the removal after the completion steps have run. I guess as long as we don't have too many callers of the algorithm it doesn't really matter.

@andreubotella
Copy link
Member Author

Tests are at web-platform-tests/wpt#31853

andreubotella pushed a commit to web-platform-tests/wpt that referenced this pull request Dec 2, 2021
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Dec 20, 2021
…ired timer is non-negative, a=testonly

Automatic update from web-platform-tests
Test that the idle deadline after an expired timer is non-negative (#31853)

Tests for whatwg/html#7377.
--

wpt-commits: 19f704c5e32a9a6ad4f1542e2228e5d0b6d727b6
wpt-pr: 31853
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Non-cancelled setTimeouts would lead to idle deadlines in the past
3 participants