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

Replace sleep_until with sleep_for to prevent clock from getting stuck with system time adjustment #1500

Merged
merged 2 commits into from
Apr 20, 2022

Conversation

RobertMueller2
Copy link
Contributor

@RobertMueller2 RobertMueller2 commented Mar 31, 2022

I think this addresses #1226 and potentially #1497.

  • observe the change in general
  • test some system time jumps
  • test the simple clock module

On FreeBSD, the change does not have any effect, but doesn't make it worse, either.

Copy link
Contributor

@alebastr alebastr left a comment

Choose a reason for hiding this comment

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

Funny (and annoying) fact: until late 2019 (gcc-mirror/gcc@ad4d1d2 - gcc 10.1, llvm/llvm-project@85e26f5 - llvm libc++ 10.0) std::condition_variable::wait_for() in both popular STL implementations was using CLOCK_REALTIME and thus had the same issue as wait_until().
The commits above addressed the issue for Linux with glibc >= 2.30, but FreeBSD, Alpine (musl) and anything else not using glibc are out of luck.

Useless trivia aside, the change improves the situation on most of the Linux distros which is already very good. Thanks!

src/modules/clock.cpp Outdated Show resolved Hide resolved
@RobertMueller2
Copy link
Contributor Author

I have tested this now and it's OK, I could not get the clock stuck on my Debian system when adjusting time. The interval alignment looked OK to me, too. With a meson file trick, I've also built and tested the simpleclock.

I've also built on alpine-latest utilizing the Dockerfile in the repo. Had to install some fonts on top -- but to my surprise it actually got along with adjusting the time just fine.

On FreeBSD, as expected, this doesn't help at all. But this has to affect the other modules using thread::sleep_for as well. I don't know if it's possible or feasible to add a lower level workaround, I don't think I could or at least not in finite amount of time. ;) The problem is not too intuitive, but it only happens under very specific circumstances where I'd say SIGUSR2 has to be good enough.

@RobertMueller2 RobertMueller2 marked this pull request as ready for review April 16, 2022 13:20
@Alexays
Copy link
Owner

Alexays commented Apr 20, 2022

Thx!

@Alexays Alexays merged commit 23369aa into Alexays:master Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants