Repository navigation
Description
-
Your Windows build number: Microsoft Windows [Version 10.0.17134.523]
-
WSL Linux Distribution: Ubuntu 16.04.5 LTS (official package installed via Windows Store)
-
What you're doing and what's happening:
Create a fileclock.c:
#include <stdio.h>
#include <time.h>
int main(int argc, char** argv) {
struct timespec now;
int ret;
ret = clock_gettime(CLOCK_MONOTONIC, &now);
printf("ret: %i\n", ret);
printf("after tv_sec: %ld\n", now.tv_sec);
printf("after tv_nsec: %ld\n", now.tv_nsec);
}
In a WSL bash.exe terminal run:
gcc clock.c
./a.out
Normally you will see something like this:
ret: 0
tv_sec: 385
tv_nsec: 449802000
However sometimes you will see something like this instead:
ret: 0
tv_sec: -2975346
tv_nsec: -412345678
(the specific values above are examples, the key point is they are negative numbers significantly less than 0)
Note that if you run the same command some seconds later, the values will have changed moving closer to 0:
ret: 0
tv_sec: -2975341
tv_nsec: -12345678
I have not had the patience to wait for the number to return to 0 to see what happens next.
This problem does not just affect this toy example.
Example 1:
In WSL bash.exe:
sudo apt-get install ruby.irbsleep 1
Normal behaviour:
2.5.1 :001 > sleep 1
=> 1
Behaviour when issue occurs:
Ruby interpreter crashes referencing pthread_cond_timedwait EINVAL.
Example 2:
In WSL bash.exe:
ssh -v -v -v -v -v <any valid hostname that allows ssh connections>.- A large stream of debug messages will be shown, but at the end you will see a message like "%s: chan %d: skip for %d more seconds" where %d is a large positive integer.
- ssh session never finishes opening, so you never get a terminal prompt etc.
I have checked the source code of both ruby and openssh-client, and I can trace the errors back to usages of clock_gettime(CLOCK_MONOTONIC) and then the values being uses assuming that tv_sec and tv_nsec are non-negative.
- What's wrong / what should be happening instead:
Sometimes, theclock_gettimesyscall withclockid_tCLOCK_MONTONIC, will fill out thetimespecfieldstv_secandtv_nsecwith negative (signed) integers, instead of (signed) integers >= 0.
I am not 100% if the relevant spec specifies this requirement exactly, but in practice, many applications assume that the tv_sec and tv_nsec fields filled in by clock_gettime(CLOCK_MONTONIC, &now) will be non-negative integers.
Normally the value of these fields for this clock seems to be the length of time since the LxssManager Windows service has been started, this seems like OK behaviour to keep in all circumstances.
When this problem occurs, there is a workaround:
- Close all open instances of bash.exe (i.e. any applications using WSL)
- On the Windows host, type Win+R, type
services.msc, press Enter. - Locate
LxssManagerand restart the service. - Open bash.exe and rerun any command that relies on the value of
clock_gettime(CLOCK_MONTONIC, &now), and see that the values are now sane.
FYI my Windows host system had been up for 34 days and 7 hours when this issue occured, so perhaps there is some connection to a long system uptime and this issue occuring.
This is NOT the same issue as #506 OR #1023 as this error occurs with CLOCK_MONTONIC, not CLOCK_MONTONIC_RAW.
This is NOT the same issue as #2503 as that is referencing CLOCK_REALTIME, not CLOCK_MONTONIC.
Activity
benhillis commentedon Feb 12, 2019
Thanks for filing, I suspect you are hitting #3434 and variants. To confirm, the issue should go away when you reboot your machine (or restart the lxssmanager service).
yecril71pl commentedon May 3, 2019
This issue makes SeaMonkey (or any other gthread-based application) crash because the makers of glib assumed that monotonic time cannot be negative (which is sort of documented, albeit no too explicitly).
Note that a clock that wraps is not a monotonic clock.
therealkenc commentedon May 3, 2019
dupe #3434
yecril71pl commentedon May 3, 2019
#3434 is about CLOCK_BOOTTIME.
therealkenc commentedon May 3, 2019
What is your Win10 ver.
yecril71pl commentedon May 4, 2019
Win10 ver. 1803
therealkenc commentedon May 4, 2019
The fix-in tag was 1809
yecril71pl commentedon May 4, 2019
That fact, while very entertaining, does not make this one a duplicate.