Skip to content

WSL2 date incorrect after waking from sleep #5324

Closed

Description

  • 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.

Activity

  1. benhillis commented on Jun 3, 2020

    @benhillis
    Member

    Gary Oberbrunner (@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.

  2. dwaynebradley commented on Jun 11, 2020

    @dwaynebradley

    Gary Oberbrunner (@garyo) Ben Hillis (@benhillis) I just tried this again on my laptop (original Surface Book) and the date/time seems to be keeping up-to-date after wake up from sleep in my setup now.

    Windows: version 2004, build 19041.329
    Distro: Ubuntu 20.04
    Linux kernel version: 4.19.104-microsoft-standard

    I put my laptop to sleep for about a minute or so, woke it back up and checked the date/time again in WSL and it seems to be updated now. Probably need to try on a longer sleep timeframe just to double-check though. I'll try this again later and report back when I have a longer period to put it to sleep.

  3. dwaynebradley commented on Jun 12, 2020

    @dwaynebradley

    Follow up on my previous comment...

    I put my laptop to sleep last night. When I opened it up this morning, the first thing I did was to check the time in WSL (Ubuntu 20.04). Low and behold...it was correct!!! :-)

    For my setup at least, this appears to be fixed now.

  4. garyo commented on Jun 12, 2020

    @garyo
    Author

    Dwayne Bradley (@dwaynebradley) are you saying it's fixed by something Microsoft did, or did you install one of the workarounds such as #4245 (comment)?

  5. dwaynebradley commented on Jun 12, 2020

    @dwaynebradley

    Gary Oberbrunner (@garyo) fixed by Microsoft apparently. No workarounds on my end.

  6. dwaynebradley commented on Jun 15, 2020

    @dwaynebradley

    Well, I just tried it again today after leaving my laptop in sleep overnight and the date is way off again. Apparently it isn't fixed after all...

  7. MauriceS-gti commented on Jun 19, 2020

    @MauriceS-gti

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

  8. Balothar12 commented on Jun 20, 2020

    @Balothar12

    I'm assuming this is the same problem, but neither wsl --shutdown nor hwclock fixes it for me, so I'm not completely sure. Whenever I try to build anything (configured with cmake, built with make), I get the clock skew warning, albeit with very small times (usually below 2 seconds and quite often below 1). Interestingly it does not appear that any builds have actually failed due to this yet, things seem to be complete even after the warning appeared. I also haven't had any issues with apt yet that relate to this.

    Windows: Version 2004, build 19041.329
    Distro: Ubuntu 20.04
    Linux Kernel: 4.19.104-microsoft-standard

  9. onomatopellan commented on Jun 20, 2020

    @onomatopellan

    Manuel Pahlitzsch (@Balothar12) Are your projects on /mnt/* folders? See #4975

  10. Balothar12 commented on Jun 20, 2020

    @Balothar12

    Jonathan (@onomatopellan) Indeed they are. Didn't realize that at first since I symlinked the respective directory from my home directory and kinda forgot abut that, but yeah, the files are technically in the mounted folders. And as mentioned in #4975 the issue does not occur when the same files are actually on the Linux filesystem.

  11. garyo commented on Jun 20, 2020

    @garyo
    Author
  12. MysticRyuujin commented on Jul 18, 2020

    @MysticRyuujin

    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

  13. eajfpeters commented on Jul 23, 2020

    @eajfpeters

    Manuel Pahlitzsch (@Balothar12) and Jonathan (@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.

  14. wsy commented on Jul 28, 2020

    @wsy

    Gary Oberbrunner (@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 Ben Hillis (@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".

  15. 238 remaining items

  16. esumii commented on Mar 20, 2023

    @esumii

    Unfortunately, it does not work unless the .bashrc or the hourly cron runs.

  17. hywan9 commented on Mar 23, 2023

    @hywan9

    Same error.
    image
    image

  18. duaneking commented on Mar 23, 2023

    @duaneking

    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.

  19. dimo414 commented on Mar 23, 2023

    @dimo414

    You might want to weigh in on #8204 which is still open. Unfortunately there's more than a dozen related bugs, seemingly because this issue has been fixed and regressed multiple times, which makes tracking down the current status very hard.

  20. levrik commented on Apr 24, 2023

    @levrik

    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

  21. kumkee commented on Jul 18, 2023

    @kumkee

    The following comment by J.B. Langston (@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 J.B. Langston (@jblang) in #5324 (comment)

  22. gnantel commented on Jul 18, 2023

    @gnantel

    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 #8204 (comment)

  23. kumkee commented on Jul 18, 2023

    @kumkee

    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 #8204 (comment)

    Thank you. That's exactly what I am after.

  24. webstean commented on Sep 15, 2023

    @webstean

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

  25. lindhe commented on Oct 5, 2023

    @lindhe
  26. silvio2402 commented on Oct 16, 2023

    @silvio2402

    I tried the listed methods to fix the time not being synced, but none of them worked.
    After doing sudo ntpdate time.windows.com (you have to install ntpdate first) and then sudo service hwclock.sh reload the clock was synced successfully.

  27. kumkee commented on Oct 18, 2023

    @kumkee

    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.

  28. lzcmian commented on Dec 15, 2023

    @lzcmian

    same bug

  29. killmasud commented on Feb 11, 2024

    @killmasud

    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.

  30. mohammadriyasriyas468-png commented on Aug 12, 2025

    @mohammadriyasriyas468-png

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions