WSL: WSL2 date incorrect after waking from sleep

  • Your Windows build number (run ver at a Windows Command Prompt), your distribution (f.e. on Debian/Ubuntu run lsb_release -r), and whether the issue manifests on WSL 2 and/or WSL 1 (cat /proc/version):

Windows: version 2004, build 19041.264 Distro: Ubuntu 18.04 Issue manifests only on WSL2 (Linux version 4.19.84-microsoft-standard)

  • What you’re doing and what’s happening. Copy&paste the full set of specific command-line steps necessary to reproduce the behavior, and their output. Include screenshots if that helps demonstrate the problem:

I upgraded an Ubuntu 18.04 WSL1 instance to WSL2. Ever since then, the date does not advance when the machine is asleep or hibernating. To repro:

  • Install Ubuntu 18.04
  • Check that Windows system date is correct
  • Check that date is correct (use date command in WSL2)
  • Put laptop to sleep for a while
  • Resume from sleep
  • Check Windows date: correct
  • Check WSL2 date: wrong, still where it was when machine went to sleep
  • Wait a while to see if it auto-corrects
  • Notice that it doesn’t

What’s wrong / what should be happening instead:

  • Date does not update after sleep. It should be correct after resume, as it was in WSL1.

Note that there was a previous issue on this topic, #4245 which is now closed, I’m not sure why; it was recommended there by @therealkenc that I open a new issue.

There are temporary workarounds; if I use sudo hwclock -s or shut down the WSL2 VM with wsl --shutdown and restart, the time is correct, until the next sleep/hibernate.

As noted in various other issues on this topic (#5184, #4975, #4677 etc.), the time being incorrect is more than a minor inconvenience. It can cause trouble with apt install, validity of SSL certs, build problems, and many other issues.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 159
  • Comments: 259 (17 by maintainers)

Commits related to this issue

Most upvoted comments

We’ve identified the root cause of this issue! This is caused by a Linux kernel bug, that has been fixed at https://kernel.org (patch 1 and patch 2). We’re working on building a new kernel version that will include these changes, and will then be making that new kernel version available via Microsoft Update as per usual! I’ll post any updates to this thread when I have them. 😃

It’s been a year and a half and they still haven’t fixed this? disappointing.

A year and a half? I just checked my WSL clock and it’s only 6 months ago!

I’ll be updating this thread since it’s the original. Just wanted to give the small update that we have a repro for this internally and are currently taking a look at debugging that to see what could be causing this.

I have enabled systemd and timesyncd and I haven’t had a problem since. I don’t have to run any commands to manually update the clock or futz with power settings. Enabling systemd does have the downside that WSL takes considerably longer to start the first time, but it’s a small price to pay.

  • To do this, first add this to /etc/wsl.conf:
    [boot]
    systemd=true
    
  • Then, in /lib/systemd/system/systemd-timesyncd.service, comment out this line:
    #ConditionVirtualization=!container
    
  • Now run wsl --shutdown from a PowerShell tab, and then start a new Ubuntu tab.
  • Once it starts up run systemctl status systemd-timesyncd and make sure the status is Active (running)
  • Hopefully, your clock now stays in sync.

Even though I have a workaround it’s still frustrating that so many people have this issue and nobody from Microsoft has responded…

@craigloewen-msft can you please help here? Is someone looking into this? Thirty people have reported this just since the beginning of the year. If there is another open issue where progress is being made, I haven’t found it.

Hi folks, the new 5.10 kernel version is live for Windows Insiders on the fast ring! This kernel version fixes the clock skew sync issue. You can update to it by clicking ‘Check for Updates’ or running wsl --update, you’ll need to be on the latest insider builds to access this Linux kernel version.

Please don’t post more “me too” comments (creating unnecessary notification noise). Just thumbs-up this message for your “me too”.

Seeing this issue daily now on windows 11.

(It is 14:00 CST)

$ wsl -e sudo hwclock -s
$ wsl -e date
Sun Nov 20 06:35:32 CST 2022
$ wsl --status
Default Distribution: Ubuntu
Default Version: 2
$ wsl --version
WSL version: 1.0.0.0
Kernel version: 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
$ wsl -e  sudo ntpdate time.windows.com
20 Nov 14:01:23 ntpdate[28294]: step time server 40.119.6.228 offset 26444.133769 sec
$ wsl -e date
Sun Nov 20 14:01:32 CST 2022

Sorry, I should have clarified that running the ntpdate command just gave my WSL a more accurate time than the hwclock command. It doesn’t fix this issue permanently, and you have to manually run the command if the drift becomes too high again.

A possible alternative workaround to stuartleeks’ option (works for me on Ubuntu 18.04):

  1. Add the following to your ~/.bashrc:
sync_time(){
    if sudo echo Starting time sync in background
    then
        sudo nohup watch -n 10 ntpdate time.windows.com > /dev/null 2>&1 &
    fi
}
  1. Source your bashrc: . ~/.bashrc
  2. Run sync_time once and it should rerun the command every 10 seconds in the background indefinitely, without stopping (even after closing your WSL window). You can check this is running with the command jobs, or if you check WSL’s processes with top -d 1 you can see ntpdate being run automatically every 10s. I haven’t tested this thoroughly but my WSL is keeping accurate time even after sleep/hibernate.

You do have to rerun this every time you restart your computer. Maybe someone else can figure out how to make this fully automatic.

Fixed in the 5.10 kernel

This still isn’t fixed and this issue should not be closed.

@Mereep , we have marked this issue with the label ‘fixinbound’ to indicate that a fix is coming, but haven’t yet closed the issue. We will close this issue (and mark it as ‘fixed’) once a kernel version is available to all users that contains this fix.

Additionally, this has been a tough to solve issue that we’ve been investigating for a while. I believe we dropped the ball here by not communicating to the community here that we are still interested in solving this and are looking into different avenues on this thread while the investigations were going on. In the future I will try and actively do better to keep threads like these informed about our investigations. For any further discussion of our process on issues here and suggestions for improvement, could you please open a Github discussion thread for it (and make sure to @ me in that thread) instead of replying on this thread? I’d like to keep the comments on this thread focused only on this particular issue. And thank you for the feedback! 😃

Can confirm fully patched 2004 still has this issue. This is particularly annoying if you’re using Docker with WSL2 backend, as this drift is inherited by all containers.

@gsusI Unfortunately these are your recent search entries 😉 But I also think this issue is very important.

Newer people, it’s finally being fixed here in #10006 currently in pre-release so you can update to that or keep your workarounds until its in release and then update, i mean we’ve waited near 4 years, can wait a little longer eh? :p Here is the link to the comment, and here is the patch itself if you’re curious.

For those who are still struggling in October 2023, doing both of the following will solve the problem and save you from manually syncing every time.

  1. Set up Windows Task Scheduler - schtasks
  2. Set up systemd-timesyncd

But I agree it is still a bug.

Update in March 2024: the kernel update mentioned in @masud-abdulkadir’s reply 2 posts below does seem to fix the bug. Tested on WSL 2.1.4.0 with Kernel 5.15.146.1-2.

It really worries me that Microsoft has apparently decided that this critical security issue is a low priority, given the amount of money that Microsoft customers have spent and invested on WSL based solutions to integrate windows with their Linux platforms.

Would anybody from a cybersecurity company be willing to help create a CVE about this issue? Because it does create security issues when TLS wont connect due to time differences, and Time is as a critical security component… so if it’s not working then you can’t trust the regulatory and security compliance of the systems involved.

This is creating auditing nightmares in the real world; I can’t go into detail but I can say that it’s costing companies a lot of money and it’s creating a lot of risk for a lot of people. Fix this asap please.

Stop using Microsoft products is really the only solution that’s worked for me.

On Tue, 21 Feb 2023 at 19:44, Marcus Robinson @.***> wrote:

@benhillis https://github.com/benhillis any ideas about this? I hit this multiple times a day, and am aware of colleagues with similar issues. Thanks.

— Reply to this email directly, view it on GitHub https://github.com/microsoft/WSL/issues/5324#issuecomment-1438063138, or unsubscribe https://github.com/notifications/unsubscribe-auth/A37FZAQRIMGYXHHDMGNXTITWYR573ANCNFSM4NRUQNJQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

This problem persists.

I posted this on another issue, but adding here in case it helps anyone.

I created a workaround for this issue using Windows Events to trigger the clock sync via hwclock on resume from sleep. Originally a PowerShell script, I’ve recently updated it to a go binary (partly because that avoids the flash of a PowerShell window). Since implementing this workaround, I’ve not had any issues: https://github.com/stuartleeks/wsl-clock

Seems like a great idea using a scheduled task!

I run a single distro and only use WSL 2 so I thought it was a bit much to download the package which has a lot of overhead for my use case. My solution is to run the hwclock command straight ahead from the task. schtasks /Create /TN wsl-clock /TR "wsl.exe -u root sh -c hwclock -s" /SC ONEVENT /EC System /MO "*[System[Provider[@Name='Microsoft-Windows-Kernel-Power'] and (EventID=107 or EventID=507)]]" /F

It’s been a year and a half and they still haven’t fixed this? disappointing.

I posted this on another issue, but adding here in case it helps anyone.

I created a workaround for this issue using Windows Events to trigger the clock sync via hwclock on resume from sleep. Originally a PowerShell script, I’ve recently updated it to a go binary (partly because that avoids the flash of a PowerShell window). Since implementing this workaround, I’ve not had any issues: https://github.com/stuartleeks/wsl-clock

Second this. Not fixed. Windows 10/2004 build 19041.329

Still an issue, it’s a bug!!!

Note to folks (I was bit by this) - you may need to run wsl --update from an elevated windows shell to obtain the new kernel with fix.

To check your kernel version, use uname -r from within your linux distro. If the version isn’t greater than “5.10”, you don’t have a kernel with the fix.

I have the same issue on W10 2004 discovered when my git commits were days out of date. sudo hwclock -s works ok, but it sets my WSL time to ~60 seconds in the future. The Windows taskbar clock display is always correct when comparing with online sources.

Using ntpdate instead and running sudo ntpdate time.windows.com makes it accurate.

It doesn’t fix this issue permanently, and you have to manually run the command if the drift becomes too high again. You can try my workaround below or stuartleeks’ workaround above.

I’m not sure if I have the same issue but I have the same problem…

My workstation NEVER sleeps, but still, somehow my WSL2 Ubuntu host became 20 seconds behind…

image

sudo hwclock -s didn’t do anything, but wsl --shutdown did cause the clocks to re-sync.

Update: Checked the time again, and it’s drifted once again. It’s now 2 seconds behind. No reboots or sleep since the screenshot above

A new megathread to track this issue has been opened. MS employees have linked it from all other open issues but not from this already closed one. So I thought I’ll add this here in case someone stumbles upon this issue.

#10006

FYI, you can manually update the kernel used by WSL2 by following the method in this comment: https://github.com/microsoft/WSL/issues/5650#issuecomment-765825503 5.10.16.3 is currently the latest kernel for WSL 2 via Microsoft

For me this has fixed this issue

Why is this ticket closed if this still exists as an issue? I just stumbled into this today, and the sudo hwclock --hctosys fix did it for me, but I don’t understand why issues would be closed until they’re actually resolved in the mainline? This is still a problem for anyone on ubuntu installing LTS on stock WSL 2.

Ran make again today after resume from sleep and guess what?

make: Warning: File 'makefile' has modification time 2 s in the future

😭

I think you need a new flux capacitor…

Since it’s a few months still, I’m going to paste @Majsvaffla 's excellent workaround here - to make it easier to find since it’s buried mid-thread - that has been getting me by for the last six months:

schtasks /Create /TN wsl-clock /TR "wsl.exe -u root sh -c hwclock -s" /SC ONEVENT /EC System /MO "*[System[Provider[@Name='Microsoft-Windows-Kernel-Power'] and (EventID=107 or EventID=507)]]" /F

It will fix up the clock on power events.

I’ve been running “hwclock -s” for a while with no problems. Now I noticed the hardware clock is also wrong for some reason (windows time is right):

PS> date; wsl date; wsl sudo hwclock

Sunday, March 19, 2023 5:02:19 PM
Sun Mar 19 14:10:47 EET 2023
2023-03-19 14:10:47.906726+02:00

(Windows 11, 22H2, Build 22621.1413, kernel 5.15.90.1-microsoft-standard-WSL2)

New laptop, updated Windows 11, installed WSL2, laptop slept. WSL2 now showing yesterday’s date and my git commits are showing the wrong time and out of order. Something is still broken.

I’m still seeing clock skew on 5.10.60.1-microsoft-standard-WSL2. Is there an open issue tracking this?

I had the issue originally stated in this issue and the 5.10 kernel update fixed it. I suggest opening a new issue as the one described and experienced here was resolved.

For those of you following this, over in #6521 MSFT has acknowledged the issue after some light pestering, and has pledged to update us on progress.

I’m using Event Source - Microsoft-Windows-Kernel-General and EventID - 1 which triggers everytime Windows syncs with hardware clock, which should only run the task as needed - when time is out of sync, since not all times sleep causes time lapse…

schtasks /create /tn WSLTimeSync /tr "wsl.exe sudo hwclock -s" /sc onevent /ec system /mo "*[System[Provider[@Name='Microsoft-Windows-Kernel-General'] and (EventID=1)]]"

Might want to ensure task runs on batteries as well: Set-ScheduledTask WSLTimeSync -Settings (New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries)

See https://stackoverflow.com/questions/65086856/wsl2-clock-is-out-of-sync-with-windows/65086857#65086857

I’m aware I should write the command down and that if one day Google goes down I’ll be living in the dark age.

But, the most relevant suggestions when I type wsl in Google are these:

image

I think is time to prioritise this issue over others - the most annoying thing is the variety of shapes in which this bug presents itself - as in, variety of errors that are triggered by other programs, libraries, etc.

By the way, can we achieve # ConditionVirtualization=!container by editing the less invasive /etc/systemd/timesyncd.conf?

sudo systemctl edit systemd-timesyncd with the following contents:

[Unit]
ConditionVirtualization=
ConditionVirtualization=wsl

References: https://unix.stackexchange.com/a/737366/272577 and https://github.com/microsoft/WSL/issues/8204#issuecomment-1338334154

I am having the exact same issue. Just updated WSL2 and the issue remains still. How come that this issue can be closed?

Because it was fixed in the store preview version of WSL, tested and confirmed closed by those who reported it (including me).

We don’t yet have a full ETA for when this fix will be available. Luckily this fix is inside of the Linux kernel, so you will not need to change your Windows build number to get it. I’ll be posting updates to this thread to let users know when this new kernel is available or you can follow our kernel release notes docs page.

I just experienced this issue on a recently installed WSL2 instance and fixed it by manually running sudo hwclock -s

Is there a fix from Microsoft underway or do I need to keep on doing it manually?

Winver: 1909 (18363.1198)

Seeing the same issue here

Microsoft Windows [Version 10.0.20197.1000]
% lsb_release -r
Release:        9.5
at /proc/version
Linux version 4.19.121-microsoft-standard (oe-user@oe-host) (gcc version 8.2.0 (GCC)) #1 SMP Fri Jun 19 21:06:10 UTC 2020

Surface laptop usually sleeps, I have seen the Linux clock more than a day behind the windows clock

I am still experiencing this issue with kernel version 5.15.79.1

image

I started to receive this bug recently:

WSL version: 1.0.3.0
Kernel version: 5.15.79.1
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.963

Same issue is re-occuring. Had to hwclock -s and install chrony to keep it in check.

5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022

It’s still broken for me, with the store preview version.

Hmm, but doing sudo ntpdate time.windows.com fails with:

15 Oct 00:14:01 ntpdate[3427]: no server suitable for synchronization found

Looks like the Microsoft time sync server is down. It’s failing from Windows too. Tried time.google.com and that worked.

I am receiving this bug after Win 11 22H2 update. Reboot or --wsl shutdown seems to be a workaround

@craigloewen-msft approximately, when will normal windows users (not insiders or beta users or whatever) be able to access this new kernel update?

@garyo - Thanks for opening a new issue. We made a previous change to send clock sync packets when the system resumes from sleep, but it looks like we are not receiving those notifications in some cases. I have an ongoing conversation with the Windows Power team, it looks like they are not correctly delivering the notifications upon system resume in some cases.

Just run into the problem. Brand new laptop with the latest Windows 11 and WSL 2. Running Ubuntu.

WSL version: 1.0.3.0 Kernel version: 5.15.79.1 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.1105

Same here, I am up to date, using the Microsoft Store version of WSL2. The issue persists.

Getting this today on w11

> wsl --status
Default Distribution: Ubuntu
Default Version: 2

Kernel version: 5.10.16

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.4 LTS"
$ date
Mon Nov  7 07:42:03 CET 2022
$ sudo hwclock -s
$ date
Mon Nov  7 09:15:55 CET 2022

I’ve just received the 5.10.16.3 kernel update on Windows 10 stable 🎉

Aha, I did it again (I did follow the whole process, shutdown, install, power on) and this time it worked! I already had “Update other products” enabled.

@drkvogel It took me about the last 16 hours or so (minus a bit of sleep time) but I think I’ve been able to restore from a month-old backup and re-acquire most of the more-recent changes from github. Not upset at you so no worries. More upset at myself for not being more careful. Hope to make sure others here don’t make the same mistake I did.

I guess it will still be interesting to see if, going forward, my time syncing problems are resolved or not. I’ll update here.

Have the same problem with WSL2, winver: 20H2 19042.685

The following comment by @jblang is easily the best one. By the way, can we achieve # ConditionVirtualization=!container by editing the less invasive /etc/systemd/timesyncd.conf?

I have enabled systemd and timesyncd and I haven’t had a problem since. I don’t have to run any commands to manually update the clock or futz with power settings. Enabling systemd does have the downside that WSL takes considerably longer to start the first time, but it’s a small price to pay.

  • To do this, first add this to /etc/wsl.conf:
    [boot]
    systemd=true
    
  • Then, in /lib/systemd/system/systemd-timesyncd.service, comment out this line:
    #ConditionVirtualization=!container
    
  • Now run wsl --shutdown from a PowerShell tab, and then start a new Ubuntu tab.
  • Once it starts up run systemctl status systemd-timesyncd and make sure the status is Active (running)
  • Hopefully, your clock now stays in sync.

_Originally posted by @jblang in https://github.com/microsoft/WSL/issues/5324#issuecomment-1451150152_

Seriously, why was this issue closed?

Me too! I am on 5.15.79.1-microsoft-standard-WSL2, and I still have this problem.

wsl --status
Default Distribution: Ubuntu-22.04 
Default Version: 2

Microsoft Windows 11 Pro 10.0.22621 N/A Build 22621

Is the check with uname really necessary?

Why ~/.profile and not ~/.bashrc?

Wouldn’t sudo hwclock -s be better? It synchronizes the clock of WSL with the clock of Windows. sudo ntpdate pool.ntp.org will give a more accurate time in WSL but it would be still desynchronized from Windows clock.

Heyyo @lackovic I am using the uname check because I don’t want to run that on non-MS releases and I also don’t use a specific shell, so that’s why the profile. As for hwclock, for my usecase, that is not useful because I don’t care about Windows clock, I care that the subsystem clock shows the real time.

For those still having this problem as it seems not fixed, untill it is, I gently remind you a reliable and automatic solution tested on different machines and any windows updates or nix distros: #5324 (comment) you can also customize some options on the task properties such hidding the command promp appearing & disapearing on execution trigger.

https://github.com/microsoft/WSL/issues/5324#issuecomment-732039406 would be better since it works without network connection (though “sh -c hwclock -s” should be “/sbin/hwclock -s”: see https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Invoking-Bash ; also, to run without power, “Start the task only if the computer is on AC power” must be unchecked on the Task Scheduler of Windows).

@bengalih we are investigating this issue again, and are looking into a fix for it. I’ll post an update here once it’s available! (And if I don’t feel free to @ me again 😃 )

@wolf99 that still only works if your machine is on Windows Insider dev, right? I just tried it from a machine on a standard Windows build and after installing that update my kernel is still 5.4.72.

No, you have to follow the whole instructions of powering off your wsl instance, then installing the update, then powering it back on. My Windows version is not Insider and it has 5.10.16.3-microsoft-standard-WSL2 kernel.

Thanks @wolf99 for pointing out how to get the kernel updated manually right away.

After doing that I then removed the workaround scheduled task wsl-clock that @Majsvaffla and @oising and @drkvogel and I had previously mentioned by running this:

schtasks /Delete /TN wsl-clock

Wonder why the related thread https://github.com/microsoft/WSL/issues/4245#issuecomment-773818529 ever could be closed. This issue exists on and on and hits really all the “developers, developers, developers”.

Command: hwclock -s (run this within you bash, e.g., Debian) always helped me for my Docker-Setup. Building might be different when build steps are done within different time “zones”. Would always clean then.

Was one of the reasons, I personally quit Windows for now. Hope to be back someday.

@johnlaur To be honest, the clock icon on the left means that it is your search requests that you made earlier. I think it’s obvious that thread participants had searched for this issue in Google. I understand your pain regarding this issue, but it doesn’t mean that everybody in the world is googling the same 😃

With all due respect, I am fully aware of how Google works. I use WSL2 and Docker’s WSL2 backend as a development environment on a daily basis. Given such, one might expect every once in a while I would have a need to search for something about this subsystem. Yet I find simple and basic virtualization problems solved since the early days (I first ran VMware on a 486 Editors’s Note: It was a Pentium Overdrive in a 486 motherboard) are my most frequent searches. This is extremely disheartening. It’s been broken so long, the conspiracy theories are starting to entertain my thoughts as I pound in the command once more: “sue doo hard ware clock dash essssss!”

In an effort not to add even more to the signal to noise, I will give my own solution to this madness which is at least a little bit unique. I run the Meinberg NTP server on Windows paired with chrony with aggressive settings on the WSL2 VM. I am aware there are other creative solutions. Anyone for a round of workaround golf?

@Balothar12 and @onomatopellan I found the same issue with files on /mnt/* and using make. sudo hwclock -s does not help. After executing this command I still get warnings like make[2]: Warning: File ‘CMakeFiles/yaml-cpp.dir/depend.make’ has modification time 0.6 s in the future and make[2]: warning: Clock skew detected. Your build may be incomplete.

The warnings are not in vain. Later I found that in fact the library I had build was incomplete and I got issues using it when trying to link it to my own code. When I moved all to the Linux side and rebuild the library it was complete. I also find that i/o of files located in /mnt/* is very slow. Probably this clock warning due to sub-second lags and slow /mnt/* file handling are related.

same bug

An Absolutely Terrible Solution that still works better than anything presented so far:

In your .bashrc and (and hourly via crontab because it still cant be trusted):

sudo ntpdate time.windows.com && sudo hwclock -s

After trying a number of things the only acceptable workaround so far is placing the sources directly on the WSL file system and not on the Windows file system.

Not only this prevents the clock skew issues but also compilation seems faster.

Yup, still getting this with WSL 1.0.3 and Windows 11.

WSL version: 1.0.3.0
Kernel version: 5.15.79.1
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

Shouldn’t this issue be re-opened?

I wonder if this issue could be caused by having both the feature version of WSL and the store preview one installed.

Good call. I just uninstalled the Store preview version and it seems to have fixed it. Will come back and post updates.

EDIT: sadly this didn’t fix it. I’m back on Windows WSL only and still the date is wrong after sleep.

EDIT 2: oh wait looks like I’m back to an older kernel now. Going to try updating

image

EDIT 3: well there were no Windows updates, so I did wsl --update. And, while it updated the kernel to a newer version, it looks like I’m back on Store preview again. So probably it’s not going to fix it.

image

image

EDIT 4: After edit 3, it was broken still. BUT! After a couple of days and I think (?) one Windows update later, the issue seems to have fixed itself with no additional action from my end. I wish I could share the fix with the community but the only thing I did that might have affected it was getting Moby to run on WSL via https://gist.github.com/noelbundick/fa8a4ddec573b00f10f3b472ac2150df.

EDIT 5: I spoke too soon. Seems like it’s broken again 😦

I wonder if this issue could be caused by having both the feature version of WSL and the store preview one installed. IIRC, leaving the original one there should not be a problem, but just to be sure, I went into add/remove applications and uninstalled the feature version of the subsystem. I’ll see after the next sleep if the clock problem persists and report here.

<Edit> Note that if you don’t actually remove the WSL feature from the features applet, it will be re-installed when you do a Windows Update check. So, I unchecked that and rebooted.

I have this bug after being replaced with the Windows Store preview version (in Windows 11).

WSL version: 0.66.2.0 Kernel version: 5.15.57.1

Has there been any further movement on this? I am having a very similar issue, and I am on the most recent version of WSL2.

uname -r returns 5.10.102.1-microsoft-standard-WSL2 uname -a returns Linux DESKTOP-SELRES5 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

@CoolBots I think that’s a different issue than this one. This is about the clock pausing while the computer is asleep and not updating when it wakes back up, so the clock ends up behind, not ahead as in your case.

I think it’s clock drift - that’s my problem anyway. One computer loses a little over a second a day, the other a little under. I tried many things to get my docker desktop times in sync, including installing and upgrading Ubuntu. I was hoping this would fix it, but no. wsl -e date slips behind the windows Get-Date. I’d actually be happy if I could run hwclock -s on a cycle, but that doesn’t seem to do anything, even though hwclock at least gives me a date now. wsl --shutdown is the only resync I have. My next step is ntpdate, which is not a “good” solution as discussed in this thread.

Whether it’s a different problem or the same problem I guess depends on whether the problem is related to “sleep” or related to “sync failure”.

Ran make again today after resume from sleep and guess what?

make: Warning: File 'makefile' has modification time 2 s in the future

😭

lol, sorry. Found the msi file inside the cab.

@craigloewen-msft approximately, when will normal windows users (not insiders or beta users or whatever) be able to access this new kernel update?

We released a blog post about our kernel servicing process to accompany this release, you can find a link here. Essentially, we are data driven when it comes to kernel releases and we migrate it out to larger rings inside of the Insiders audience as we gain confidence on its quality to validate it. This makes it tough to give an exact date, but I’d say you could expect this new kernel version to be generally available within a few months to all WSL users.

Hi @craigloewen-msft,

this is good news and I appreciate that this topic is taken into account now. Thanks for that. Anyway, I really am interested in how and under which policies this problem could be ignored for almost 2 years and on top of that could be resolved as fixed: without fixing it; with all the of people saying it is (still) a problem in many threads?

I mean someone must have clicked “I fixed, close this issue; forget it forever” despite being absolutely certain, it wasn’t actually fixed and people will have related hard-to-notice problems of all sorts?

We’ve identified the root cause of this issue! This is caused by a Linux kernel bug, that has been fixed at https://kernel.org (patch 1 and patch 2). We’re working on building a new kernel version that will include these changes, and will then be making that new kernel version available via Microsoft Update as per usual! I’ll post any updates to this thread when I have them. 😃

Great news! Thanks for the investigation & fix. Loving WSL, Gives best of both worlds!

Do you have a ballpark timeline for the next WSL updates to be released on MS Update? Are there any feeds/lists that can be followed?

Fantastic news, thanks Craig and team! 😃

Same problem. Adding a comment to maybe increase the visibility to MSFT.

Also curious if others have tried/considered the crontab suggestion from OscBacon:

sudo crontab -e, then add: 10 * * * * ntpdate time.windows.com

Not sure whether adjusting the time every 10 minutes has any ill side-effects (or if cron works as expected in WSL).

This doesn’t work for me 😦

Running sudo hwclock -s does the trick though, but have to run it manually.

The problem seems to have resolved on my system, after upgrading Ubuntu (under WSL) 18.04 to 20.04 and rebooting a couple of times.

Update - upgrading/reinstalling Ubuntu did not fix it!

Do not follow my previous advice to do wsl --unregister <DistroName> as this deletes the distro rather than “unregistering” it - see above!

I’ve been using noelbundick’s hack and it does mostly work (though I’m not entirely sure how - it seem to rely on a command being entered to trigger the clock update, though the time in WSL seems usually to be correct on resume even if I haven’t entered a command since - e.g. in VS Code, I use this extension to insert a timestamp into my markdown documents and the time inserted is correct, even if I haven’t yet entered a command, so how was it triggered?).

After I upgraded my Ubuntu distro, and commenting out the hack from my ~/.zshrc, the clock issues seemed to be resolved - but I think there were still some terminals hanging around that still had the hack enabled, and that’s what kept the clock synced. After a full reboot and with no hack enabled, the clock drift still happened, so this is definitely still an issue and not solved by updating/reinstalling your distro.

@drkvogel “On workstation unlock” is a great hook. I’m already using it to deal with Elgato’s buggy implementation of sleep in their Stream Deck lineup, but didn’t think of applying the same hook to this issue. Good call!

Doesn’t work, unfortunately!

Any developer response here or do I have to still battle with this issue everyday?

@johnlaur To be honest, the clock icon on the left means that it is your search requests that you made earlier. I think it’s obvious that thread participants had searched for this issue in Google. I understand your pain regarding this issue, but it doesn’t mean that everybody in the world is googling the same 😃

image @MarkusRodler I appreciate seeing that other users have this pain too. I have over 20 years in software, and the fact that this one stupid little bug has existed unaddressed for more than a year in one form or another gives me the absolute heebie-jeebies.

@garyo - Thanks for opening a new issue. We made a previous change to send clock sync packets when the system resumes from sleep, but it looks like we are not receiving those notifications in some cases. I have an ongoing conversation with the Windows Power team, it looks like they are not correctly delivering the notifications upon system resume in some cases.

Hi @benhillis , I’d like to remind you of another scenario about clock sync packet and Windows Power state. That is NESTED VIRTUALIZATION. I got a physical computer running Hyper-V. I created a virtual machine with nested virtualization enabled and I installed Windows 10 2004 on that virtual machine. Inside Windows 10, I enabled Hyper-V and enabled WSL2. Now my Ubuntu 20.04 is 50 minutes behind my Windows 10 clock. This is possibly because the virtual machine got paused when I restarted my host machine. I guess in this scenario, Windows 10 would never have received any event notification because there’s nothing a guest OS needed to do. Thus Windows 10 would never have notified WSL2 kernel of something that’s “never happened”.

Everyone’s saying that with WSL2 you want to move your project folders into the Linux side – opposite of WSL1. Filesystem performance accessing Windows files from WSL2 is abysmal. (But this is getting off topic.)

To remind: as far as this WSL bug (delay of time) is concerned, I do not see any problem in automatically running hwclock every time the host Windows resumes.

https://github.com/microsoft/WSL/issues/5324#issuecomment-1396292234

I think this WSL clock problem must stem from Windows needing to aggressively sleep to save power. I wonder if we could just have an option to not do that? I notice, compared to my Ubuntu desktop machine on the same network, that if I lock my computer: my WSL clock will drift, but also no Outlook mails will be retrieved (have to wait for a few minutes after unlock), and any SSH sessions I have are lost. My morning routine every day for the last few months is:

  • Try: sudo hwclock -s
  • Test the time: date
  • That mostly works, but if it doesn’t, close all WSL windows and Visual Code editors that use it, then in a Windows Command prompt: wsl.exe --shutdown
  • Then log back in to everything During the day I have to run my computer with no power saving options to blank the screen. At night I can let it power off the screen to do the whole thing again the next day. I need an accurate clock for git commits and AWS CLI authentication.

This is active and just bit me on a BRAND NEW LAPTOP with Win11 Pro on WSL.

I am still experiencing this issue with kernel version 5.15.79.1 Same here, 5.15.79.1-microsoft-standard-WSL2. Fixed the time last night. Today (after laptop sleeping) it is off again.

Still happening. Can someone re-open this issue?

image

Same issue here too, also Windows 11

WSL version: 1.0.3.0
Kernel version: 5.15.79.1
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

this is just happening now that I had the Wsl Preview from the store installed. Never been an issue before.

i still unfortunately have this bug on 5.15

image

#7255 or #8204

Those two are probably not the same problem. #7255 talks about seconds off over days; #8204 is hours off overnight. #8204 looks more like a regression bug to this one.

@bpulliam it looks like this should be reopened as it seems that the 5.10 kernel has not fixed this ?

This issue is a terrible joke. I wish I could kick the next MS guy who proudly states that developers can use Linux on Windows … A team mate just wasted half a day on troubleshooting some minimal time difference (not fixable with sudo hwclock -s) which makes some integration tests run red. All tests running absolutely fine on my native Ubuntu …

Can reproduce regularly, using only the WSL filesystem btw.

As in https://github.com/microsoft/WSL/issues/4245 “sudo hwclock -s” fixes it.

Not critical once I know how to fix it, but 😃

@CoolBots I think that’s a different issue than this one. This is about the clock pausing while the computer is asleep and not updating when it wakes back up, so the clock ends up behind, not ahead as in your case.

The clock sync issue was a kernel bug that was not fixed until the 5.10 kernel. Make sure you’re running the most recent version of the kernel.

This is what works for me under Debian/Ubuntu sudo hwclock --hctosys (no need to shutdown WSL).

I used @drkvogel’s way, but with a small modification as sh -c caused it to complain with no servers can be used. I didn’t even need it as going straight in with ntpdate did the trick.

schtasks /Create /TN wsl-clock /TR "wsl.exe -u root ntpdate time.windows.com" /SC ONEVENT /EC System /MO "*[System[Provider[@Name='Microsoft-Windows-Kernel-Power'] and (EventID=107 or EventID=507)]]" /F

btw, hwclock -s is not very accurate, for some reason - it often sets the WSL clock to about a minute into the future - better to use ntpdate, e.g. ntpdate time.windows.com, so the workaround above might be better as:

schtasks /Create /TN wsl-clock /TR "wsl.exe -u root sh -c ntpdate time.windows.com" /SC ONEVENT /EC System /MO "*[System[Provider[@Name='Microsoft-Windows-Kernel-Power'] and (EventID=107 or EventID=507)]]" /F

although I haven’t tested it yet - it requires an internet connection rather than syncing to the hardware clock, so I’m not sure if that’s going to work at power on.

Same problem. Adding a comment to maybe increase the visibility to MSFT.

Also curious if others have tried/considered the crontab suggestion from OscBacon:

sudo crontab -e, then add: 10 * * * * ntpdate time.windows.com

Not sure whether adjusting the time every 10 minutes has any ill side-effects (or if cron works as expected in WSL).

Very relieved to hear that! Sorry about the time spent and any recent data lost, I owe you a beer or three!

The clock issue now seems trivial, but would be interesting to hear, yes…

@getify Just for future knowledge, I regularly “backup” my WSL distribution using the wsl --export command. If you use the integrated backup/restore functionality that comes in Settings -> Update & Security, sadly that normally doesn’t include the location of the WSL distros that you have installed.

Here is a blog by Scott Hanselman on how to use --export and --import to move your “perfect” WSL setup between machines:

https://www.hanselman.com/blog/easily-move-wsl-distributions-between-windows-10-machines-with-import-and-export

This technique works really well for simply backing up your WSL instances as well.

@drkvogel welp… I didn’t realize that the --unregister command you suggested would actually delete my entire wsl image. It uninstalled the wsl distribution, so the subsequent --set-default command failed because there was no longer any installed distros. I had to reinstall from Windows Store, and that created a whole new image.

Apparently I just blew away a whole bunch of stuff in my old image, and I have no idea if I can get it back. I’m going to go hunting in a previous system backup to see if there’s a way to export that backed up image and re-import.

Caveat Emptor here. I shouldn’t have run that command without understanding what it was going to do. Beware others.

I’ve not seen the issue for the couple of days, after it being a daily thing previously. Not calling it fixed, more trying to understand what changed

~~I like the PowerShell/Go workaround above, but I wanted something running natively in the WSL2 VM. This is what I cooked up. It polls the hardware clock every minute, and if the clock has drifted more than 5 seconds, it syncs the VM to the hardware clock: https://github.com/muchtall/muchtall-scripts/blob/master/wsl2-time-sync.txt~~

Not as quick as triggering on wake from hibernate, but it’s close enough for my needs.

EDIT: Nevermind. I got into work today, and noticed that it’s not working. Not sure why it worked when I was developing the solution, but it’s not working for me now. 🤷‍♂️

Still present in W10 2004 (Build 19041.508). This was a fun rabbit-hole to dive down.