Skip to content

Platform differences on timers when OS is asleep #316

@schultetwin1

Description

@schultetwin1

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions