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

Platform differences on timers when OS is asleep #316

Closed
schultetwin1 opened this issue Sep 9, 2022 · 0 comments · Fixed by #317
Closed

Platform differences on timers when OS is asleep #316

schultetwin1 opened this issue Sep 9, 2022 · 0 comments · Fixed by #317

Comments

@schultetwin1
Copy link
Contributor

boringtun relies on on std::time::Instant to deal with handshake timeout, session timeout, keep-alive, etc. Under the hood, std::time::Instant uses the following APIs (https://doc.rust-lang.org/std/time/struct.Instant.html#underlying-system-calls)

Windows => QueryPerformanceCounter
macOS => mach_absolute_time
Linux => clock_gettime

These timers do not exhibit the same behavior when the OS is asleep

Windows:

QueryPerformanceCounter reads the performance counter and returns the total number of ticks that have occurred since the Windows operating system was started, including the time when the machine was in a sleep state such as standby, hibernate, or connected standby.

https://docs.microsoft.com/en-us/windows/win32/sysinfo/acquiring-high-resolution-time-stamps

macOS:

this clock does not increment while the system is asleep.

https://developer.apple.com/documentation/kernel/1462446-mach_absolute_time

Linux (I couldn't find any docs).

I think std::time::Instant maybe the wrong clock to use here? My main concern is macOS. After waking from sleep the timers are not properly updated.

There is already a change out for rust std::time::Instant here: rust-lang/rust#88714

schultetwin1 pushed a commit that referenced this issue Sep 10, 2022
Currently the timers in boringtun use std::time::Instant. This timer
does not increment while the machine is asleep on macOS and Linux
meaning the device does not know to properly handshake on wake from
sleep.

To solve this we use `CLOCK_BOOTTIME` on Linux/Android and
`CLOCK_MONOTONIC` on macOS/iOS to get the actual duration since the last
handshake.

Fixes #316
schultetwin1 pushed a commit that referenced this issue Sep 10, 2022
Currently the timers in boringtun use std::time::Instant. This timer
does not increment while the machine is asleep on macOS and Linux
meaning the device does not know to properly handshake on wake from
sleep.

To solve this we use `CLOCK_BOOTTIME` on Linux/Android and
`CLOCK_MONOTONIC` on macOS/iOS to get the actual duration since the last
handshake.

Fixes #316
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 a pull request may close this issue.

1 participant