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

WSL2 date incorrect after waking from sleep #8204

Closed
1 of 2 tasks
q3769 opened this issue Mar 29, 2022 · 106 comments
Closed
1 of 2 tasks

WSL2 date incorrect after waking from sleep #8204

q3769 opened this issue Mar 29, 2022 · 106 comments

Comments

@q3769
Copy link

q3769 commented Mar 29, 2022

Version

Microsoft Windows [Version 10.0.22581.100]

WSL Version

  • WSL 2
  • WSL 1

Kernel Version

5.10.102.1

Distro Version

Release: 20.04

Other Software

No response

Repro Steps

  1. Leave the Windows system untouched until it goes to sleep.
  2. Wait for a while, say an hour.
  3. Wake up the computer, and type "date" in WSL 2 shell

Expected Behavior

WSL 2 date should be the same as Windows date.

Actual Behavior

WSL 2 date is way behind and slower than the Windows date.

Diagnostic Logs

No response

@mcollier
Copy link

mcollier commented Mar 29, 2022

I'm noticing the same thing. For me, WSL2 time was in sync with the Windows time until I updated to use the Windows Store version of WSL. Now, whenever my PC resumes from sleep, the WSL2 time is minutes to hours behind.

To "fix", I will wsl --shutdown and then restart WSL.

Default Distribution: Ubuntu-20.04
Default Version: 2
WSL version: 0.56.2.0
Kernel version: 5.10.102.1
WSLg version: 1.0.30
MSRDC version: 1.2.2924
Direct3D version: 1.601.0
Windows version: 10.0.22581.100

@q3769
Copy link
Author

q3769 commented Mar 29, 2022

Yes, this is a regression bug after I updated to the latest Win11 beta push. I also found an earlier bug of the same nature #5324

@longfield-tech
Copy link

Same for me (Ubuntu 20.04)

WSL version: 0.56.2.0
Kernel version: 5.10.102.1
WSLg version: 1.0.30
MSRDC version: 1.2.2924
Direct3D version: 1.601.0
Windows version: 10.0.22581.200

@ionutvilie
Copy link

ionutvilie commented Apr 12, 2022

same error; for me, this is not related system going to sleep, the clock is desynchronizing even if my terminal is in the background.

PS C:\Users\xxxxx> date ; wsl date
12 April, 2022 09:17:54
Mon Apr 11 21:13:21 EEST 2022

PS C:\Users\xxxxx> wsl -v
WSL version: 0.58.0.0
Kernel version: 5.10.102.1
WSLg version: 1.0.32
MSRDC version: 1.2.2924
Direct3D version: 1.601.0
Windows version: 10.0.22593.1

@dboreham
Copy link

Also seeing this here on ARM64 with the latest Win11 insiders beta build and latest WSL2 kernel:

PS C:\Users\david> systeminfo /fo csv | ConvertFrom-Csv | select OS*, System*, Hotfix* | Format-List


OS Name             : Microsoft Windows 11 Pro
OS Version          : 10.0.22598 N/A Build 22598
OS Manufacturer     : Microsoft Corporation
OS Configuration    : Standalone Workstation
OS Build Type       : Multiprocessor Free
System Boot Time    : 4/17/2022, 9:27:16 AM
System Manufacturer : Microsoft Corporation
System Model        : Surface Pro X
System Type         : ARM64-based PC
System Directory    : C:\WINDOWS\system32
System Locale       : en-us;English (United States)
Hotfix(s)           : 3 Hotfix(s) Installed.,[01]: KB5007297,[02]: KB5014100,[03]: KB5014104



PS C:\Users\david> wsl uname -a
Linux cambridge1 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux
PS C:\Users\david> date

Sunday, April 17, 2022 9:13:56 PM


PS C:\Users\david> wsl date
Sun Apr 17 12:06:40 MDT 2022
PS C:\Users\david>

Somewhat more annoying is that the usual workaround hwclock -s no longer appears to work:

PS C:\Users\david> wsl -u root hwclock -s
hwclock: Cannot access the Hardware Clock via any known method.
hwclock: Use the --verbose option to see the details of our search for an access method.
PS C:\Users\david>

@dylanwa
Copy link

dylanwa commented Apr 26, 2022

This is a really annoying issue!

It blocks any application you're developing with Auth function; you'll get this error message:
"The ID token is not yet valid. Make sure your computer's time and time zone are both correct."

> wsl uname -r
5.10.102.1-microsoft-standard-WSL2

wsl datetime is totally out of sync with System datetime

>  Get-Date; wsl date

Monday, April 25, 2022 10:53:11 PM
Mon Apr 25 22:37:05 PDT 2022

@dylanwa
Copy link

dylanwa commented May 12, 2022

Found a workaround, set up a Windows scheduled task to update Ubuntu datetime when machine wake up from sleep.
#4149

@RobCannon
Copy link

RobCannon commented Aug 4, 2022

It looks like this is fixed in release https://github.com/microsoft/WSL/releases/tag/0.65.1!

EDIT:
Or not. I have that version installed, but I am still seeing clock skew issues.

EDIT2:
So those release notes say:
Use /dev/ptp0 to keep guest chock in sync with the host

Is there anything that need to be done to configure this to make it work?

@kforeverisback
Copy link

Created a function which I can call at my convenience:

update_clock () {
        echo '[ROOT] Updating clock (sudo hwclock --hctosys)'
        sudo hwclock -s
        sudo ntpdate time.windows.com
}

Since, hwclock -s no longer works consistently, I've ntpdate time.windows.com, that works as of today.

@heaths
Copy link
Member

heaths commented Sep 22, 2022

sntp time.windows.com didn't work while my machine was in this state - soon after updating to the Windows Store version via wsl --upgrade. I ended up having to shutdown WSL and restart it.

@heaths
Copy link
Member

heaths commented Oct 4, 2022

Not sure if it helps, but I hadn't experienced this problem for a while after the original bug was fixed (back when sudo hwclock -s worked) until I upgraded from the MSI-installed WSL2 kernel to the Store-installed package per the prompt I was getting when logging into my distro.

@Annih
Copy link

Annih commented Oct 7, 2022

@heaths what version do you have exactly?

I upgraded recently both Windows and my WSL but I still get out of sync clock when restoring my session from sleep/hibernate.

My versions:

Kernel version: 5.15.57.1
WSLg version: 1.0.42
MSRDC version: 1.2.3401
Direct3D version: 1.606.4
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.521

@tsteven4
Copy link

tsteven4 commented Oct 7, 2022

I still loose clock sync with
WSL version: 0.66.2.0
Kernel version: 5.15.57.1
WSLg version: 1.0.42
MSRDC version: 1.2.3401
Direct3D version: 1.606.4
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.608

@heaths
Copy link
Member

heaths commented Oct 10, 2022

@heaths what version do you have exactly?

WSL version: 0.66.2.0
Kernel version: 5.15.57.1
WSLg version: 1.0.42
MSRDC version: 1.2.3401
Direct3D version: 1.606.4
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.521

@tsteven4
Copy link

I'm still losing sync, now with:

WSL version: 0.70.0.0
Kernel version: 5.15.68.1
WSLg version: 1.0.45
MSRDC version: 1.2.3575
Direct3D version: 1.606.4
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.674

@ternst-micado
Copy link

Same issue here, date and time out of sync after sleep.

WSL version: 0.70.0.0
Kernel version: 5.15.68.1
WSLg version: 1.0.45
MSRDC version: 1.2.3575
Direct3D version: 1.606.4
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.674

@sabaronett
Copy link

sabaronett commented Oct 20, 2022

Same.

WSL version: 0.70.0.0
Kernel version: 5.15.68.1
WSLg version: 1.0.45
MSRDC version: 1.2.3575
Direct3D version: 1.606.4
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.674

@pacanukeha
Copy link

pacanukeha commented Oct 20, 2022

Same

WSL version: 0.70.0.0
Kernel version: 5.15.68.1
WSLg version: 1.0.45
MSRDC version: 1.2.3575
Direct3D version: 1.606.4
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.675

@cubeleo
Copy link

cubeleo commented Nov 3, 2022

This is a constant friction when trying to develop inside WSL2. Running make, clock skew warnings clog the build output.

@tage64
Copy link

tage64 commented Nov 3, 2022

I agreee, it sucks.

I get all sorts of strange errors due to the clock being incorrect. Sometimes the clipboard hangs, sometimes I can't connect to internet, and sometimes hwclock -s rewinds the clock even further.

Imagine you could do the same thing with the physical REAL time. Rewind the time and rewrite history! That'd be really COOL!

@nwsparks
Copy link

nwsparks commented Nov 4, 2022

with systemd now available i've installed ntp as a workaround and just restart the service after sleep. still annoying though.

@haroldiedema
Copy link

sudo hwclock -s no longer works after updating. The latest kernel patch only seemed to fix it when the WSL machine initially boots, but as soon as the host machine comes back from sleep, the time is skewed again. Using hwclock -s used to fix this, but this also no longer works.

In practice, the patch made things (much) worse...

@derkoe
Copy link

derkoe commented Dec 2, 2022

Same here with 1.0.0.0

WSL-Version: 1.0.0.0
Kernelversion: 5.15.74.2
WSLg-Version: 1.0.47
MSRDC-Version: 1.2.3575
Direct3D-Version: 1.606.4
DXCore-Version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows Version: 10.0.22621.819

@wpwoodjr
Copy link

wpwoodjr commented Dec 5, 2022

I worked around this by configuring the systemd-timesyncd service under systemd. Note, this approach seems to modify the time in the parent WSL VM, as such it corrects the time in all WSL distro instances, so probably you only want to implement this in one instance.

First you have to enable systemd for this to work:

Set the systemd flag set in your WSL distro settings
You will need to edit the wsl.conf file to ensure systemd starts up on boot.

Add these lines to the /etc/wsl.conf (note you will need to run your editor with sudo privileges, e.g: sudo nano /etc/wsl.conf):

[boot]
systemd=true

And close out of the nano editor using CTRL+O to save and CTRL+X to exit. Now close your WSL distro windows and run wsl.exe --shutdown from PowerShell, then restart your WSL instance. Upon launch you should have systemd running.

Now install systemd-timesyncd:

sudo apt install systemd-timesyncd
sudo systemctl edit systemd-timesyncd

In the second step, when editing, add the two lines beginning with [Unit], as shown below:
image

Now start it:

sudo systemctl start systemd-timesyncd

Check status with:

timedatectl status
timedatectl timesync-status

@RobCannon
Copy link

That seems to work for me! I automated the configuration in our setup script with this:

# Fix time sync issues in WSL
# https://github.com/microsoft/WSL/issues/8204#issuecomment-1338334154
sudo mkdir -p /etc/systemd/system/systemd-timesyncd.service.d
sudo tee /etc/systemd/system/systemd-timesyncd.service.d/override.conf > /dev/null <<'EOF'
[Unit]
ConditionVirtualization=
EOF
sudo systemctl start systemd-timesyncd

@heaths
Copy link
Member

heaths commented Dec 6, 2022

What are the downsides to running systemd? While I used linux almost exclusively many, many years ago, that predates systemd and all I've seen around the net is hate but haven't really seen why.

@marbaa
Copy link

marbaa commented Apr 6, 2023

This is ridiculous. WSL2 was set as future approach and this one year old, pretty serious bug is still there.

WSL version: 1.1.6.0
Kernel version: 5.15.90.1
WSLg version: 1.0.50
MSRDC version: 1.2.3770
Direct3D version: 1.608.2-61064218
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.1413

/usr/sbin/hwclock -s not working, have to do wsl --shutdown

@shivshanks
Copy link

I think I have a way of reliably reproducing this if anyone from the Microsoft Linux kernel team is watching this thread.

The key seems to be running WSL2 inside Windows itself running in a Hyper-V VM. Running directly on a Windows host doesn't have the problem. In my problematic case, it's WSL2 running in a Windows 10 VM inside a Windows 11 host. WSL2 kernel and windows are all updated to the latest. Perhaps something is getting lost in the VM inside an VM scenario?

When I get some time, I will try to reproduce this on another machine with this VM inside a VM scenario.

Feel free to contact me if any traces/logs are needed.

@wpwoodjr
Copy link

wpwoodjr commented Apr 9, 2023

I think I have a way of reliably reproducing this if anyone from the Microsoft Linux kernel team is watching this thread.

The key seems to be running WSL2 inside Windows itself running in a Hyper-V VM. Running directly on a Windows host doesn't have the problem. In my problematic case, it's WSL2 running in a Windows 10 VM inside a Windows 11 host. WSL2 kernel and windows are all updated to the latest. Perhaps something is getting lost in the VM inside an VM scenario?

When I get some time, I will try to reproduce this on another machine with this VM inside a VM scenario.

Feel free to contact me if any traces/logs are needed.

I had this issue under Windows 11 on a laptop. For a solution see #8204 (comment)

@shivshanks
Copy link

I think I have a way of reliably reproducing this if anyone from the Microsoft Linux kernel team is watching this thread.
The key seems to be running WSL2 inside Windows itself running in a Hyper-V VM. Running directly on a Windows host doesn't have the problem. In my problematic case, it's WSL2 running in a Windows 10 VM inside a Windows 11 host. WSL2 kernel and windows are all updated to the latest. Perhaps something is getting lost in the VM inside an VM scenario?
When I get some time, I will try to reproduce this on another machine with this VM inside a VM scenario.
Feel free to contact me if any traces/logs are needed.

I had this issue under Windows 11 on a laptop. For a solution see #8204 (comment)

Yes, thanks, I did see that. Not sure of Windows 11 is a factor. I haven't seen the issue on a Windows 10 laptop with WSL2 running directly on it.

I'm hoping the kernel or VM team can address this issue so folks don't need to look for workarounds.

@captainfalcon23
Copy link

I am having this issue since moving to Windows 11. Using a fresh install of Win 11, WSL, Oracle Linux 7.9. Every time the host sleeps, the time skews out. Here's an example:

[XXX ~]$ date
Thu Apr 13 18:51:23 AEST 2023
[XXX ~]$ sudo ntpdate time.windows.com
[sudo] password for XXX:
14 Apr 09:15:15 ntpdate[3858]: step time server 52.148.114.188 offset 51816.353629 sec
[XXX ~]$ date
Fri Apr 14 09:16:53 AEST 2023

And right now, can't implement Chrony or anything similar to #8204 (comment) due to #9961 :( :( :(

@craigloewen-msft
Copy link
Member

/dupe #10006

We're migrating all clock skew issues to a megathread so we can keep the top comment up to date with any updates and work arounds. Thank you for filing this!

@microsoft-github-policy-service
Copy link
Contributor

Hi! We've identified this issue as a duplicate of another one that already exists in this repository. This specific instance is being closed in favor of tracking the concern over on the referenced thread.

Thanks for your report!

@rebroad
Copy link

rebroad commented May 9, 2023

I'm having this issue also.

C:\Users\rebroad>wsl -v
WSL version: 1.2.5.0
Kernel version: 5.15.90.1
WSLg version: 1.0.51
MSRDC version: 1.2.3770
Direct3D version: 1.608.2-61064218
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.1555

@edyu
Copy link

edyu commented May 17, 2023

I use the following to fix the problem now:

sudo apt install chrony
sudo systemctl restart chrony.service

You do need to install systemd by adding the following lines to /etc/wsl.conf and restart wsl with wsl --shutdown before al this:

[boot]
systemd=true

@leonaAtkins
Copy link

I have this problem.
I've resorted to adding a cron job to update the system clock every hour.

@taufderl-anvil
Copy link

Why is this issue closed, I still have this problem every day

> wsl -v
WSL version: 1.2.5.0
Kernel version: 5.15.90.1
WSLg version: 1.0.51
MSRDC version: 1.2.3770
Direct3D version: 1.608.2-61064218
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.2134

@dboreham
Copy link

Why is this issue closed, I still have this problem every day

It was closed, and a new bug opened, because people kept posting workarounds here (the problem itself needs to be fixed, not worked around). See: #8204 (comment)

@troy-mac
Copy link

troy-mac commented Sep 12, 2023

@dboreham, then let's get on it, Microsoft!!! This is insane, over a year people have been complaining
and the problem still exists, pretty unacceptable if you ask me.
WSL version: 1.2.5.0
Kernel version: 5.15.90.1
WSLg version: 1.0.51
MSRDC version: 1.2.3770
Direct3D version: 1.608.2-61064218
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.2134

@daglees
Copy link

daglees commented Sep 24, 2023

I'm also experiencing this.

WSL version: 1.2.5.0
Kernel version: 5.15.90.1
WSLg version: 1.0.51
MSRDC version: 1.2.3770
Direct3D version: 1.608.2-61064218
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.2283

@lackovic
Copy link

Now start it:

sudo systemctl start systemd-timesyncd

Do we need to start it manually every time we open WSL?

Check status with:

timedatectl status
timedatectl timesync-status

What's the expected result of these commands? When I run them they give me a bunch of information but it's unclear if they have any effect:

$ timedatectl status
               Local time: Wed 2023-09-27 17:57:39 EEST
           Universal time: Wed 2023-09-27 14:57:39 UTC
                 RTC time: Wed 2023-09-27 14:57:37
                Time zone: Europe/Tallinn (EEST, +0300)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

$ timedatectl timesync-status
       Server: 185.125.190.58 (ntp.ubuntu.com)
Poll interval: 32s (min: 32s; max 34min 8s)
         Leap: normal
      Version: 4
      Stratum: 2
    Reference: 5617C31E
    Precision: 1us (-25)
Root distance: 4.172ms (max: 5s)
       Offset: +366.242ms
        Delay: 33.236ms
       Jitter: 507.117ms
 Packet count: 3
    Frequency: -33.471ppm

timesync-status says there is an offset but it's always the same if I run the command multiple consecutive times. When I ran after a few minutes it gives a different offset and it never say if it actually adjusted the time to the correct one.

@simonerlandsen
Copy link

simonerlandsen commented Sep 28, 2023

[boot]
systemd=true

this breaks opening vscode from wsl with code .

WhitewaterFoundry/Pengwin#635

@wpwoodjr

@wpwoodjr
Copy link

@simonerlandsen I'm not seeing that in Ubuntu:
image

@wpwoodjr
Copy link

@lackovic

Do we need to start it manually every time we open WSL?

No

What's the expected result of these commands? When I run them they give me a bunch of information but it's unclear if they have any effect:

Just to be sure everything is running. Looks good in your case. Just check the WSL time once in awhile to verify its correct.

@simonerlandsen
Copy link

simonerlandsen commented Sep 28, 2023

@simonerlandsen I'm not seeing that in Ubuntu

Okay, I guess it's not universal, but others has the same issue as me with it, so fair warning

I have Ubuntu as well btw

@russd2357
Copy link

az login fails because time is incorrect. Here's what I did to try and fix it, but was unsuccessful. Normally hwclock -s will remedy the situation, but every now and then it looks like WSL gets stuck and I have to reboot to fix it. Personally, I don't think this issue should be closed.

error

@ghost
Copy link

ghost commented Oct 31, 2023

It's closed because it's marked as a duplicate. I'm locking this thread.

@ghost ghost locked as off-topic and limited conversation to collaborators Oct 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests