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

Timer is paused on Android in "doze" state #63

Open
link2xt opened this issue May 9, 2021 · 6 comments
Open

Timer is paused on Android in "doze" state #63

link2xt opened this issue May 9, 2021 · 6 comments

Comments

@link2xt
Copy link

link2xt commented May 9, 2021

Because std::time::Instant is implemented using libc::clock_gettime(CLOCK_MONOTONIC) and this time does not advance on Android while the app is in "doze" state, the timer may be effectively paused on Android: https://users.rust-lang.org/t/std-now-with-android/41774

One way to fix this is to use SystemTime instead and handle time occasionally going backwards properly. Another is to lift this issue to the standard library so it uses Android-specific ioctl on /dev/alarm as described here: https://users.rust-lang.org/t/std-now-with-android/41774/2

@taiki-e
Copy link
Collaborator

taiki-e commented May 10, 2021

Another is to lift this issue to the standard library so it uses Android-specific ioctl on /dev/alarm as described here:

See rust-lang/rust#71860

@nullchinchilla
Copy link

nullchinchilla commented Nov 26, 2021

Commenting to note that this behavior is actually desirable in my use case, as it prevents massive thundering-herds of timers suddenly expiring when Doze ends, something I've seen in Go.

My use case does involve massive amounts of small, fine-grained timers (essentially a userspace TCP implementation), so it's somewhat of a worst-case for this though.

@notgull
Copy link
Member

notgull commented Aug 19, 2022

With Rust 1.64 coming out in a month or so, this issue should be fixed on libstd relatively soon. I'd rather wait for it to be fixed on that end than implement a patch in here that will soon become unnecessary.

@notgull
Copy link
Member

notgull commented Sep 23, 2022

As of Rust 1.64, the Instant type now uses CLOCK_BOOTTIME, which should close this issue.

@notgull notgull closed this as completed Sep 23, 2022
@notgull
Copy link
Member

notgull commented Sep 23, 2022

Actually, I just remembered that polling uses CLOCK_MONOTONIC, so I should reopen this issue until that is fixed.

@notgull notgull reopened this Sep 23, 2022
@link2xt
Copy link
Author

link2xt commented Sep 24, 2022

As of Rust 1.64, the Instant type now uses CLOCK_BOOTTIME, which should close this issue.

This URL points to line with CLOCK_MONOTONIC, and if I switch to master, it's still CLOCK_MONOTONIC. Where does the Instant implementation use CLOCK_BOOTTIME constant?

There is a PR proposing a switch to CLOCK_BOOTTIME, but it's not merged: rust-lang/rust#88714

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants