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 clock becomes unsynced on Desktop system #7255

Closed
1 of 2 tasks
gitbls opened this issue Jul 31, 2021 · 22 comments
Closed
1 of 2 tasks

WSL2 clock becomes unsynced on Desktop system #7255

gitbls opened this issue Jul 31, 2021 · 22 comments

Comments

@gitbls
Copy link

gitbls commented Jul 31, 2021

Windows Build Number

Microsoft Windows [Version 10.0.19043.1110]

WSL Version

  • WSL 2
  • WSL 1

Kernel Version

5.10.16.3-microsoft-standard-WSL2

Distro Version

Debian 10

Other Software

No response

Repro Steps

I restarted my Desktop (a Dell box, nothing funky) 3 days ago after installing the latest WSL update. At that point, the date/time in my Debian WSL was spot on with the rest of the world.

Now, 3 days later, it's off by 7 or 8 seconds.

I tried sudo hwclock -s but no joy. It didn't reset the time in WSL.

Expected Behavior

Clock stays in sync, or there's a reasonable workaround to keep it in sync.

Actual Behavior

Time falls behind about 2 seconds per day.

Diagnostic Logs

Filled out the info in Windows Feedback and added a screenshot of two dclocks: a blue clock running on my chrony server, and a green dclock running in WSL2 Debian. As you can see, the time in the WSL2 Debian system is 7 seconds behind reality.

@anacierdem
Copy link

The same is true for me as well. Even after the 5.10.16.3 kernel update the clocks does not stay in sync. Doing a wsl sudo hwclock -s does not fix it either. I'm using ubuntu 18.04.

@rob3c
Copy link

rob3c commented Dec 13, 2021

Are either of you running Windows in a VM and using your hypervisor to suspend it? I explained my solution to clock sync issues with using WSL2 in a Windows guest VM using Parallels on a Mac this comment:
#5324 (comment)

@anacierdem
Copy link

No, the wsl2 host is on bare metal for me.

@gitbls
Copy link
Author

gitbls commented Dec 13, 2021

No, this is on a Windows desktop system bare metal that I never sleep or hibernate,

@shanz1999
Copy link

shanz1999 commented Dec 15, 2021

I updated the WSL kernel version using cabinet and msi files but the date and time was still drifting after pausing the VMWare VM which contains my Windows 10 and WSL.
Instead I have created my own solution as follows -
in WSL
/home/myuser/.bashrc

add these lines at the end so WSL bash runs the powershell script, syncdates,ps1 everytime WSL bash is opened.

# fix wsl time sync
powershell.exe -File "c:\Users\myuser\syncdates.ps1"

The script syncdates.ps1 is

echo "Running syncdates.ps1..."
#syncdates.ps1 can be run on startup 
# save current Windows host's time and date into variable $TimeStr
$TimeStr = Get-Date -Format "MMddHHmmyy.ss"
# eg: wsl sudo date 1115204821.10 => Mon Nov 15 20:48:10 GMT 2021
wsl sudo date $TimeStr

I then added /usr/bin/date to my sudoers file to avoid having to keep typing the password.

@trevor-scheer
Copy link

Is anyone working around this in a way that doesn't require manual intervention? I'm fairly new to wsl and this is a major inconvenience. And is this somehow not affecting everyone? I'd expect an issue like this to have a lot of traction.

@ben-page
Copy link

ben-page commented Mar 2, 2022

Yes, this is pretty big inconvenience. It needs to be fixed.

@yorickdowne
Copy link

yorickdowne commented Apr 3, 2022

I see this on a Win11 on baremetal that's been configured to stay in sync by making sure w32time starts and MaxPollInterval is set, as per https://eth-docker.net/docs/Support/Windows . date in Powershell matches https://time.is. However, date in WSL2 Ubuntu 20.04 with kernel 5.10.102.1-microsoft-standard-WSL2 is two seconds off, in this case it was two seconds fast. In my case, sudo hwclock -s does resolve this clock skew.

For anything Windows not-domain-joined, first, the host time sync needs to be fixed, as it is Terribad(tm) out of the box. From there, there's still an issue of WSL2 getting out of sync without scheduled hwclock -s intervention: schtasks /Create /TN WSL2TimeSync /TR "wsl -u root hwclock -s" /SC ONEVENT /EC System /MO "*[System[Provider[@Name='Microsoft-Windows-Kernel-Power'] and (EventID=107 or EventID=507) or Provider[@Name='Microsoft-Windows-Kernel-General'] and (EventID=1)]]" /F

@ghost ghost self-assigned this Apr 19, 2022
@ghost ghost added the bug label Apr 19, 2022
@ghost
Copy link

ghost commented Apr 19, 2022

/logs

@ghost
Copy link

ghost commented Apr 19, 2022

Hello! Could you please provide more logs to help us better diagnose your issue? You can find instructions on how to attach logs here, please make sure to post the link to the Feedback Hub item in this chat so we can see it.

Thank you!

@mcollier
Copy link

@owenschupp When would be the most helpful time to gather the logs? Would it be after the PC resumes from sleep and the WSL clock is out of sync with Windows?

@ghost
Copy link

ghost commented Apr 20, 2022

@mcollier that would be a great time, thanks for bringing that up!

@dlchet
Copy link

dlchet commented Apr 24, 2022

i started a recording, let my surface book go to sleep, waited a few minutes, woke it up, confirmed the clock had lagged, and stopped recording. let me know if i should re-do this in a different way to be more helpful. also i'm on the beta preview build if that matters. thanks for any insight into how to get the wsl clock to stay synced!

https://aka.ms/AAgr1pp

@gitbls
Copy link
Author

gitbls commented Apr 27, 2022

As I noted in OP, my scenario requires that it run for up to 24 hours before the clock skew becomes obvious. I'm not sure how to show that the clock is skewed without doing a video, but seems that would make a rather large recording.

How little skew would you find compelling as a demonstration that the clock is not in sync?

@ghost ghost removed the needs-author-feedback label Apr 27, 2022
@wolf99
Copy link

wolf99 commented Jun 28, 2022

I'm still seeing this issue also.

Also on Windows 10 (21H2) with WSL 2.

I remember back in the hazy halcyon days of #4245, #4975, #4677, #5324, et al, where we still held out hope that this issue may actually be fixed. Whole internet eons have ground by since then... 😉

@gitbls
Copy link
Author

gitbls commented Jul 7, 2022

My W10 Desktop with Debian 10 WSL has been up for 3 weeks. I just updated the date/time in WSL and it was off by 28+ seconds.

bls@MS-eagle~> sudo ntpdate 192.168.92.3
 7 Jul 06:58:23 ntpdate[1637]: step time server 192.168.92.3 offset 28.769070 sec
bls@MS-eagle~> uptime
 06:58:28 up 21 days,  1:08,  0 users,  load average: 0.02, 0.01, 0.00
bls@MS-eagle~> 

The system is always up (no sleep, hibernate, etc).

@s-boris
Copy link

s-boris commented Nov 16, 2022

I'm still seeing this issue also.

Also on Windows 10 (21H2) with WSL 2.

I remember back in the hazy halcyon days of #4245, #4975, #4677, #5324, et al, where we still held out hope that this issue may actually be fixed. Whole internet eons have ground by since then... 😉

Yea the clock does not seem to ever get synced after startup. Especially putting your pc to sleep desyncs the time so much that I can't even interface with a lot of external API's which is super annoying. There are a lot more people still reporting and commenting on those issues like #5324

@James34Shaw100
Copy link

Also seeing this since I updated to Windows 11 after working fine on Windows 10. Hibernating the machine overnight means the clock will be out of sync.

However interestingly, the clock is not out of sync by the amount of time the system was shut down for as one might expect. Instead, when running a command today at around ~12:45pm, running date showed the clock as being 10:14am or so, only an hour and a bit's drift.

sudo hwclock -s does fix the issue and reset the clock.

Running Ubuntu 20.04.5 LTS with kernel 5.15.68.1-microsoft-standard-WSL2.

@aylusltd
Copy link

aylusltd commented Mar 10, 2023

sudo hwclock -s does fix the issue and reset the clock.

Not anymore. Now the WSL clock is a half hour ahead.
WSL2; Ubuntu 22.04; Win11.

Update:
sudo apt install ntpdate
sudo ntpdate 0.pool.ntp.org

worked for me. Adding that to crontab to run every half hour should keep you plenty synced.

@gitbls
Copy link
Author

gitbls commented Mar 11, 2023

Once WSL2 supported systemd enablement I turned that on, and enabled systemd-timesyncd. To make that work I copied /lib/systemd/systemd/systemd-timesyncd.service to /etc/systemd/system and commented out this line thusly

#ConditionVirtualization=!container

Time seems to stay in sync and I've noticed no side effects.

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests