Skip to content

WSL2: Clock skewed? #4677

Closed
Closed

Description

This is found on WSL2.

Please fill out the below information:

  • Your Windows build number: (Type ver at a Windows Command Prompt)

Version 1903 Build 19018.1

  • What you're doing and what's happening: Clock way off.

  • What's wrong / what should be happening instead: Clock should be in sync with the host.

Windows taskbar clock says 5:22pm
WSL Linux (Ubuntu) date: says 05:09:23 PST

The clock appears to be about 12 hours 13 minutes off? I don't see any obvious ways to resolve this as ntpdate is not installed by default, there's no systemd-style init process that would run ntpd/etc.

The net impact is that time-sensitive things like credential or request signing will all appear expired by the receiver because my requests are signed "12 hours ago" ;)

Thoughts?

Activity

  1. jordansissel commented on Nov 14, 2019

    @jordansissel
    Author

    wsl --shutdown seems to be a workaround:

    % date                                    
    Wed Nov 13 08:31:08 PST 2019              
    % exit
    PS C:\Users\whack> wsl --shutdown         
    PS C:\Users\whack> wsl                    
    % date                                    
    Wed Nov 13 20:44:00 PST 2019              
    
  2. benhillis commented on Nov 14, 2019

    @benhillis
    Member

    You should also be able to use sudo hwclock -s from within the Linux environment.

  3. therealkenc commented on Nov 14, 2019

    @therealkenc

    Fair to say we're calling this different than #4245 (message)? Asking because the other one is tag fixininsiders, and I've lost the script on what was (contrast wasn't) addressed in 18970.

  4. benhillis commented on Nov 14, 2019

    @benhillis
    Member

    therealkenc - Specifically large skews when resuming from sleep should be fixed, but small skews that accumulate during runtime may still be an issue.

  5. jishi commented on Dec 18, 2019

    @jishi

    This is still a problem in Microsoft Windows [Version 10.0.19037.1]

    The machine have been running WSL2 for some days, the clock in WSL2 is:

    07:59 $ date
    Tue 17 Dec 2019 08:03:49 AM CET
    

    And in windows

    C:\Users\jayja>date /t                                                                                                  2019-12-18                                                                                                                                                                                                                                      C:\Users\jayja>time /t                                                                                                  15:15      
    

    This is running the debian distro which supposedly has a hwclock.sh service running, but doesn't seem to sync. Running sudo hwclock -s manually does sync the time, so maybe it's a distro problem?

  6. vbaderks commented on Feb 1, 2020

    @vbaderks

    Just updated to Windows 10 build 19041.21 to start to use WSL-2
    I am getting a warning on WSL-2 when building a C++ project on a NTFS drive from withing WSL-2:

    make[2]: Warning: File 'samples/convert.cpp/CMakeFiles/convert-cpp.dir/depend.make' has modification time 0.022 s in the future
    make[2]: warning: Clock skew detected. Your build may be incomplete.

    WSL-1 has never reported these warnings on the same configuration.

  7. JurrianFahner commented on Mar 14, 2020

    @JurrianFahner

    I need to set the time every time my laptop was in hibernate.
    Can something done, so the time within WSL has an auto sync capability with the host.

    Workaround for me is to use ntpdate, but I think it should not needed. To work properly.

    image

  8. rupor-github commented on Mar 16, 2020

    @rupor-github

    Windows 10 build 19041.153 attempting to use WSL2, files are on Windows file system (not rootfs):

    -- Build files have been written to: /mnt/e/projects/misc/wsl-ssh-agent/release
    make: Warning: File 'Makefile' has modification time 0.6 s in the future
    make[1]: Warning: File 'CMakeFiles/Makefile2' has modification time 0.65 s in the future
    make[2]: Warning: File 'CMakeFiles/bin_agent.dir/progress.make' has modification time 0.61 s in the future
    Scanning dependencies of target bin_agent
    make[2]: warning:  Clock skew detected.  Your build may be incomplete.
    make[2]: Warning: File 'CMakeFiles/bin_agent.dir/progress.make' has modification time 0.51 s in the future
    [100%] Building wsl-ssh-agent-gui...
    make[2]: warning:  Clock skew detected.  Your build may be incomplete.
    [100%] Built target bin_agent
    make[1]: warning:  Clock skew detected.  Your build may be incomplete.
    
  9. firewave commented on May 28, 2020

    @firewave

    That seems to be an Hyper-V issue instead of an WSL one.

    I have had issues with time on Hyper-V instances ever since. Any time I wake up my machine from sleep I have to manually run ntpdate to get the proper time. I tried setting up the ntp service, but that didn't seem to work at all (might have been my fault, but I used the default configuration and got no errors and no time synchronization at all). Rebooting the instance fixes it but IIRC the hardware clock sync is performed during that.

  10. added
    needs-investigation
    on Jun 3, 2020
  11. firewave commented on Jun 4, 2020

    @firewave

    While checking dmesg for my WSL 2 Kali instance I saw the following:

    [    0.533293] hv_utils: cannot register PTP clock: 0
    
  12. Justin-DynamicD commented on Jun 15, 2020

    @Justin-DynamicD

    adding that I see this issue as well. I don't see a clear pattern between shutdown vs hibernate, but occasionally clock sensitive operations will fail until I re-sync (AWS or Azure CLI for example).

  13. MauriceS-gti commented on Jun 19, 2020

    @MauriceS-gti

    I still see this issue using Windows 10/2004 build 19041.329. HOURS of difference:

    PS C:\src\cs> date
    Friday, June 19, 2020 11:40:07 AM
    [/workspaces]$ date [docker-native:localhost]
    Thu Jun 18 21:30:29 MDT 2020

  14. gbro3n commented on Jul 24, 2020

    @gbro3n

    To add this is causing problems when running AWS cli commands when my Windows machine running WSL2 has slept.

    For example:

    aws ecr get-login-password

    Results in an error like

    (InvalidSignatureException) when calling the GetAuthorizationToken operation: Signature expired: <DATE> is now earlier than <DATE> (<DATE> - 15 min.)

  15. nbdd0121 commented on Oct 5, 2020

    @nbdd0121

    Ben Hillis (@benhillis) Running sudo hwclock on WSL2 gives a drifted clock, different from NTP & Windows Time.

    $ sudo hwclock && date && cmd.exe /c time
    2020-10-05 23:33:43.950559+01:00
    Mon 05 Oct 2020 11:33:50 PM BST
    The current time is: 23:33:50.09
    Enter the new time:
    

    EDIT: WSL2 uptime is 5 days without sleep.

  16. frke242 commented on Dec 4, 2020

    @frke242

    Microsoft Windows [Version 10.0.18363.1198]

    When I try to build with cmake I get the following warning:
    Run Build Command(s):/usr/sbin/make cmTC_6952b/fast && make: Warning: File 'Makefile' has modification time 0.53 s in the future

    I tried building both in the shared filesystem, i.e. /mnt/c and in my home folder in the wsl2 installation. Same issue.

    Running date +%T.%N && cmd.exe /c time gives:
    08:10:27.146163000
    The current time is: 8:10:27,79

  17. gkochera commented on Jan 19, 2021

    @gkochera

    Running 19041.746 with Ubuntu 20.04.1 LTS and GNU Make 4.2.1

    Tried all the mentioned possible fixes included in this thread including rebooting, wsl --shutdown, and the shell commands listed. The clock in W10 and Ubuntu are definitely at least to the second matched up.

    Still get this error when running make. Haven't observed it with other utilities yet.

    UPDATE: I was able to discern that the clock skew is about 0.43 to 0.45 seconds. I can sync windows time and try to 'make' right after, and the issue is still present.

  18. nbdd0121 commented on Jan 20, 2021

    @nbdd0121

    I wrote a program to workaround this problem: https://github.com/nbdd0121/wsld. Assuming you don't also need X11 forwarding, you can put

    [time]

    in ~/.wsld.toml, and follow the instructions there to setup automatic startup.

    It will sync time from Windows every 10 minutes, and will adjust time like NTP.

  19. yanrez commented on Mar 30, 2021

    @yanrez
    Member

    This is dup of #5324

  20. therealkenc commented on Mar 31, 2021

    @therealkenc

    /dupe #5324

  21. ghost closed this as completedon Mar 31, 2021
  22. nbdd0121 commented on Mar 31, 2021

    @nbdd0121

    I don't think this is a dupe; I've seen my clock drifting without sleep or hibernation.

  23. jordansissel commented on Mar 31, 2021

    @jordansissel
    Author
  24. Animeshz commented on May 7, 2021

    @Animeshz

    Since this issue pops first from google, Issue comment 5650 here's how one can install the update 😁, this has fixed the issue for me 😄

  25. scottshambaugh commented on Nov 21, 2022

    @scottshambaugh

    I ran into this today,
    ERROR: Clock skew detected. File /mnt/c/Users/Scott/Documents/Documents/Coding/scipy/build/meson-private/coredata.dat has a time stamp 42373.3841s in the future.
    and the sudo hwclock -s command fixed it. Might have had something to do with not restarting since the daylight savings time switch?

  26. edmoman commented on Feb 6, 2023

    @edmoman

    I keep receiving the message even after trying the hwclock and touch workarounds.

    The problem seems to be that the files generated during compiling have a timestamp 2-4 second in the future.

    This seems as a major bug to me.

    Keep in mind that most companies block the Microsoft Store and implement proxies that block NTP.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateneeds-investigation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions