WSL: Time not synced in WSL2 - causing TLS issues
Please use the following bug reporting template to help produce issues which are actionable and reproducible, including all command-line steps necessary to induce the failure condition. Please fill out all the fields! Issues with missing or incomplete issue templates will be closed.
If you have a feature request, please post to the UserVoice.
If this is a console issue (a problem with layout, rendering, colors, etc.), please post to the console issue tracker.
Important: Do not open GitHub issues for Windows crashes (BSODs) or security issues. Please direct all Windows crashes and security issues to secure@microsoft.com. Ideally, please configure your machine to capture minidumps, repro the issue, and send the minidump from "C:\Windows\minidump".
Please fill out the below information:
-
Your Windows build number: [Version 10.0.18917.1000]
-
What you’re doing and what’s happening:
Was having issues with SSL certificates in k8s “Unable to connect to the server: x509: certificate has expired or is not yet valid” Spent ages debugging on servers. Turned out the time in my WSL2 prompt I was using to access the external cluster had the wrong time. In WSL2 (ubuntu build)
rob@SUSE-Dell:~$ date
Sat Jun 15 10:08:45 BST 2019
In Windows (run literally 1 second after)
PS C:\Users\rob> date
15 June 2019 22:24:14
- What’s wrong / what should be happening instead: Date should be synced up, as it was for WSL1
Not sure if the OS image makers should be dealing with this, but I guess if things are running in some kind of VM now some kind of time drift will happen (this issue wasn’t happening ~12hrs ago). This ubuntu image was converted from WSL1 > 2.
Solved my issues for now running a manual ntp sync (which is sudo ntpdate -b time.google.com for anyone interested, but with the lack of systemd/daemon I’ll have to keep doing this every time the drift gets too great. In other vm platforms there’s mechanisms in place for keeping time in sync and as a user it would be good to have the system take care of this autoamtically
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 27
- Comments: 24
@rssfed23 @zigford This works for Ubuntu in WSL 2, without losing your running processes. (should also work in most distros, though you’d need to use your own package managers)
Then run
sudo ntpdate -sb time.nist.goveach time you want to correct the drift.I left my laptop sleep for a few days with a WSL2 distro open. When I resumed tonight, the date was out of sync by 2 days. My distro did not have ntpdate installed, and apt-get tools were failing due to TLS issues. Workaround:
wsl --shutdownto force the VM to close and then reopen WSLHi all, I created a script that creates a scheduled task to automatically update the time of WSL when you either restore from sleep or you restore a “Saved” Hyper-V VM.
Change
Ubuntu(in both places in the script) to the name of your WSL Instance (Seewsl --list), then execute the script incmd.Thanks to all the other comments/suggestions that helped me create this script 😄 .
I’m confused. This still isn’t fixed as of 19033.1 using WSL2. Manually fixing the drift by running a command is not a resolution to the problem since it will just get out of sync again.
Further testing. time “freeze” only occurs if you have a WSL window open when the laptop sleeps.
This other issue seems to be tracking the same problem: https://github.com/microsoft/WSL/issues/5324 for those landing here from Google
@paulosoares86 you could assign a
NOPASSWDin a/etc/sudoersfile. My.bash_profilerunssudo hwclock -s. Then in/etc/sudoers.d/username_hwclockStill occurs.
Solution is to switch to a working Linux Machine and throw Microsoft from system
ntpdate works on my desktop.
run
sudo ntpdate time.windows.comcould it be automatically?
Hello, after the recent Win 11 update, the problem reappeared on Ubuntu in WSL 2, only hwclock -s helps.
Adding voice to the opinion that this should not be closed. Using WSL2 and if I shutdown my laptop, WSL2 will drift implying that it doesn’t know how to recover from having no hwclock.
I’ve not tested different distros to see if perhaps that’s to blame, but ubuntu 18.04 LTS definitely has the problem.
I’m running into massive drift: it’s 13:49 as reported by Windows and 23:54 as reported by WSL 2 in build 18995.