-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
LibCore: Single-shot timer is fired twice #3641
Comments
cc @DanShaders , is this an artifact of your Timer refactor from a while back? Context from the fix in 3188
|
Possibly-relevant original commits: Switch from select to poll: SerenityOS/serenity@6836091 (SerenityOS/serenity#23046) Timer refactor: SerenityOS/serenity@120d6b2 (SerenityOS/serenity#23149) |
This ... feels unfortunate. Calling spin_until from an event callback. Outside of fixing this specific double-firing bug for single-shot timers, we should think about how to avoid doing that. Maybe it can't be avoided, maybe importing the coroutine stuff from Serenity would help serialize things, etc. |
Oh yeah, thanks for linking all commits from that refactor (My brain is currently unable to understand write-up you linked, try again later, i. e. I'll look into this tomorrow) |
There is a delay between firing a timer event and executing a handler for that event. In EventLoopImplementationUnix the situation is possible when event for a single-shot timer is posted to ThreadEventQueue, then handler for another event calls pump again (indirectly through spin_until) and the same timer fires again. I noticed that because on Windows it results in infinite spinning in spin_until called from TraversableNavigable::check_if_unloading_is_canceled, see commit "LibCore: Make single-shot timer objects manually reset on Windows" in #3188 for more info.
After applying this patch the command
Meta/ladybird.sh run headless-browser
has this output on Ubuntu 22.04:patch
I propose this fix: add a state "awaiting execution" to the timer, which is set to true when it fired, set to false when it is executed, and don't fire again if "awaiting execution" is true. Change Web::HTML::EventLoop::schedule to create a new timer each time it is called instead of using m_system_event_loop_timer.
The text was updated successfully, but these errors were encountered: