WSL icon indicating copy to clipboard operation
WSL copied to clipboard

nanosleep sleeps less than request time

Open Rob2309 opened this issue 1 month ago • 1 comments

Windows Version

Microsoft Windows [Version 10.0.26200.7171]

WSL Version

WSL-Version: 2.6.1.0

Are you using WSL 1 or WSL 2?

  • [x] WSL 2
  • [ ] WSL 1

Kernel Version

6.6.87.2-microsoft-standard-WSL2

Distro Version

Ubuntu 24.04

Other Software

No response

Repro Steps

Run the following rust program:

use std::{thread::sleep, time::Duration};

use chrono::Utc;

fn main() {
    loop {
        let now = Utc::now();
        println!("Then: {now:?}");

        sleep(Duration::from_secs(10));

        let now = Utc::now();
        println!("Now: {now:?}");

        println!();
    }
}

Expected Behavior

nanosleep should sleep at least the amount specified.

Actual Behavior

This simple rust program regularly prints sleep times less than 10 seconds, which should be impossible, according to the rust docs and the documentation of the underlying nanosleep syscall.

Then: 2025-11-28T17:43:48.713270129Z
Now: 2025-11-28T17:43:58.715972419Z

Then: 2025-11-28T17:43:58.716082411Z
Now: 2025-11-28T17:44:07.138078919Z   <<< less than 10s

Then: 2025-11-28T17:44:07.138195931Z
Now: 2025-11-28T17:44:17.147807293Z

This breaks programs like code tunnel, because it simply sends requests too fast:

[2025-11-28 17:40:06] trace refresh poll failed, retrying: Error getting authorization: authorization_pending The authorization request is still pending.
[2025-11-28 17:40:11] trace refresh poll failed, slowing down
[2025-11-28 17:40:20] trace refresh poll failed, slowing down

The slowing down messages only occur when sending requests faster than the interval specified by the server. I traced this problem down to a sleep call in vscode.

This problem happens on my laptop, but not on my desktop. However, it seems to be unrelated to hibernation, as it also happens after a full system restart or wsl --shutdown.

Diagnostic Logs

No response

Rob2309 avatar Nov 28 '25 17:11 Rob2309

Logs are required for review from WSL team

If this a feature request, please reply with '/feature'. If this is a question, reply with '/question'. Otherwise, please attach logs by following the instructions below, your issue will not be reviewed unless they are added. These logs will help us understand what is going on in your machine.

How to collect WSL logs

Download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:

Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1
Set-ExecutionPolicy Bypass -Scope Process -Force
.\collect-wsl-logs.ps1

The script will output the path of the log file once done.

If this is a networking issue, please use collect-networking-logs.ps1, following the instructions in Collect WSL logs for networking issues

Once completed please upload the output files to this GitHub issue.

See Collect WSL logs (recommended method).

If you choose to email these logs instead of attaching them to the bug, please send them to [email protected] with the GitHub issue number in the subject, and include a link to your GitHub issue comment in the message body, and reply with '/emailed-logs'.

github-actions[bot] avatar Nov 28 '25 17:11 github-actions[bot]

This issue has been automatically closed since it has not had any author activity for the past 7 days. If you're still experiencing this issue please re-file it as a new issue.

Thank you!