Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WSL1] [glibc] sleep: cannot read realtime clock: Invalid argument #4898

Closed
hferreira23 opened this issue Feb 14, 2020 · 141 comments
Closed

[WSL1] [glibc] sleep: cannot read realtime clock: Invalid argument #4898

hferreira23 opened this issue Feb 14, 2020 · 141 comments

Comments

@hferreira23
Copy link

Windows build number: Microsoft Windows [Version 10.0.18362.592]
WSL version: 1
Linux distro: Arch WSL

Description:

I'm using Arch WSL in WSL 1 and after an update which bumped glibc from 2.30.3 to 2.31.1 the sleep command stopped working throwing out the error: sleep: cannot read realtime clock: Invalid argument

This affects namely as Ansible, as ansible runs sleep commands in multiple modules. In this issue, on the Arch WSL github (yuk7/ArchWSL#108) , some problems with rust packages were also identified.

Downgrading to the previous version solves the issue. Now, I know that Arch WSL is not an official WSL implementation but this may actually happen when Ubuntu, etc, reach the aforementioned version of glibc

@sirredbeard
Copy link
Contributor

sirredbeard commented Feb 14, 2020

Annotation 2020-04-27 131743

Guidance on this issue in Ubuntu on WSL1 is here: https://discourse.ubuntu.com/t/ubuntu-20-04-and-wsl-1/15291:

What is the plan?

For WSL 1 users, I recommend you sit tight on Ubuntu 18.04 for now. The patch for issue 4989 will take some time to be backported. Ubuntu 18.04 is an LTS release, short for long-term servicing, and is supported through 2023 so you will continue to get security patches and backports from Canonical in the meantime.

Workarounds include:

If you need to reset Ubuntu and are on WSL 1, you should switch to the Ubuntu 18.04 image.


I can confirm upgrading glibc from 2.30.3 to 2.31.1 on Arch on WSL breaks sleep.

Annotation 2020-02-14 180116

I used the Arch rootfs from the ArchWSL project: https://github.com/yuk7/ArchWSL/releases/download/20.2.7.0/Arch.zip

Imported it.

Confirmed 2.20.3 installed:

$ pacman -Q --info glibc

In /etc/pacman.conf changed SigLevel= to Never.

Ran updates:

$ pacman -Syu

Confirmed new version:

$ pacman -Q --info glibc

Tried $ sleep 10. Got came error.

strace attached.
sleep10.txt

@sirredbeard
Copy link
Contributor

sirredbeard commented Feb 15, 2020

It looks like sleep used to call:

nanosleep({tv_sec=10, tv_nsec=0}, NULL) = 0

sleep10-glibc2.30-3.txt

Appears that support for nanosleep was added in 14915.

But now calls:

clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=10, tv_nsec=0}, NULL)

sleep10-glibc2.31-1.txt

The line in sleep is here: https://github.com/coreutils/coreutils/blob/master/src/sleep.c#L142

if (xnanosleep (seconds))

Here are the release notes for glibc 2.31.1, they mention some changes related to clock issues but nothing jumps out as directly related: https://sourceware.org/ml/libc-announce/2020/msg00001.html

Also this may all technically be a duplicate of #2503

@therealkenc
Copy link
Collaborator

therealkenc commented Feb 15, 2020

Also this may all technically be a duplicate of #2503

Most def. Apologies I saw this submission and knew it was dupe #2503 earlier in the afternoon, but got pulled away before I could hit the button. Thanks for going down the rabbit hole.

I'll forward-dupe #2503 as a (probably bad precedent) bump. If this is in glibc it'll hit distros in the store soon enough. Presumably eating CLOCK_REALTIME but providing CLOCK_MONOTONIC semantics in the WSL1 driver would be a pretty small change.

@sirredbeard
Copy link
Contributor

sirredbeard commented Feb 15, 2020

Between glibc 2.30 and 2.31 they add the following to /posix/nanosleep.c:

{
  int ret = __clock_nanosleep (CLOCK_REALTIME, 0, requested_time, remaining);
  if (ret != 0)
    {
      __set_errno (ret);
      return -1;
    }
  return 0;
}

@therealkenc
Copy link
Collaborator

Right, this.

@sirredbeard
Copy link
Contributor

sirredbeard commented Feb 15, 2020

Here an interesting related email thread:

POSIX.1 specifies that nanosleep() should measure time against the
   CLOCK_REALTIME clock.

@therealkenc
Copy link
Collaborator

Yeah. Ref.

@dbz2k
Copy link

dbz2k commented Feb 15, 2020

I was wondering would issues like these get backported to with cumulative updates, or I would I have to wait till the next window version.

@sirredbeard
Copy link
Contributor

I spoke with one of the senior engineers on our foundations team and they do plan to land glibc 2.31, with the problematic change, in Ubuntu Focal 20.04, our next release in April.

This one would be a useful to have backported unless it can be fixed upstream.

@dbz2k
Copy link

dbz2k commented Feb 24, 2020

sorry for commenting again I was wondering if there were going to have wait till the next window version to get it fixed?

@SvenGroot
Copy link
Member

As @therealkenc surmised, the issue is the lack of CLOCK_REALTIME support in WSL1's clock_nanosleep. We have a fix working internally, which will make its way to insiders. We will also look into backporting this to older Windows versions, but I can't make any promises or provide a timeline for this, unfortunately.

@kailiu42
Copy link

kailiu42 commented Mar 2, 2020

I believe this is the problem that caused 100% CPU utilization on a single core for the cron process on my system. It used to run well until a few days ago the cron daemon process suddenly always on 100% CPU core usage. I checked my system it indeed has glibc upgraded to 2.31 on Feb 20. Then I straced cron process, it keeps calling clock_nanosleep(CLOCK_REALTIME, ...) indefinitely, might be the problem that caused high CPU utilization.

@ChrisTX
Copy link

ChrisTX commented Mar 6, 2020

I've gotten 2.31 to work fine on my Arch install by recompiling the package with a patch to __clock_nanosleep replacing CLOCK_REALTIME with CLOCK_MONOTONIC:

diff -ruN glibc-2.31/sysdeps/unix/sysv/linux/clock_nanosleep.c glibc-2.31-b/sysdeps/unix/sysv/linux/clock_nanosleep.c
--- glibc-2.31/sysdeps/unix/sysv/linux/clock_nanosleep.c	2020-02-01 12:52:50.000000000 +0100
+++ glibc-2.31-b/sysdeps/unix/sysv/linux/clock_nanosleep.c	2020-03-05 23:51:05.856886500 +0100
@@ -31,7 +31,8 @@
                           struct __timespec64 *rem)
 {
   int r;
-
+  if (clock_id == CLOCK_REALTIME)
+	  clock_id = CLOCK_MONOTONIC;
   if (clock_id == CLOCK_THREAD_CPUTIME_ID)
     return EINVAL;
   if (clock_id == CLOCK_PROCESS_CPUTIME_ID)

If anyone's feeling adventurous, feel free to try this out.

@therealkenc
Copy link
Collaborator

therealkenc commented Mar 6, 2020

I've gotten 2.31 to work fine on my Arch install by recompiling the package with a patch

Close. You've got to be careful about TIMER_ABSTIME in flags. A straight-up swap of CLOCK_REALTIME for CLOCK_MONOTONIC probably isn't (quite) enough. [This is possibly academic for the quick fix; no one sane uses TIMER_ABSTIME. It might not even matter IRL, it would take some test cases to confirm.]

@ChrisTX
Copy link

ChrisTX commented Mar 13, 2020

I've gotten 2.31 to work fine on my Arch install by recompiling the package with a patch

Close. You've got to be careful about TIMER_ABSTIME in flags. A straight-up swap of CLOCK_REALTIME for CLOCK_MONOTONIC probably isn't (quite) enough. [This is possibly academic for the quick fix; no one sane uses TIMER_ABSTIME. It might not even matter IRL, it would take some test cases to confirm.]

That's a valid point, but clock_nanosleep(CLOCK_REALTIME, ...) has always been broken on WSL, and that includes with TIMER_ABSTIME. It's easily fixable by subtracting the current CLOCK_REALTIME value from the absolute timestamp and dropping the TIMER_ABSTIME flag. I've expanded the patch to that end, but I really doubt this has any practical impact or use. I've uploaded the patch as a Gist.

@saizai
Copy link

saizai commented Mar 14, 2020

This breaks Ubuntu Focal also.

# uname -a
Linux [redacted] 4.4.0-18362-Microsoft #476-Microsoft Fri Nov 01 16:53:00 PST 2019 x86_64 x86_64 x86_64 GNU/Linux

# wslsys
Release Install Date: 0x5ceea999
Branch: 19h1_release
Build: 18363
Full Build: 18362.1.amd64fre.19h1_release.190318-1202
Uptime: 6d 4h 6m
Linux Release: Ubuntu Focal Fossa (development branch)
Linux Kernel: Linux 4.4.0-18362-Microsoft
Packages Count: 1367

# apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 libc-bin : Depends: libc6 (< 2.31) but 2.31-0ubuntu5 is installed
 libc-dev-bin : Depends: libc6 (< 2.31) but 2.31-0ubuntu5 is installed
 libc6-dev : Depends: libc6 (= 2.30-0ubuntu3) but 2.31-0ubuntu5 is installed
 locales : Depends: libc-bin (> 2.31) but 2.30-0ubuntu3 is installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

# apt --fix-broken install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  libc-bin libc-dev-bin libc6-dev libcrypt-dev
Suggested packages:
  glibc-doc
The following NEW packages will be installed:
  libcrypt-dev
The following packages will be upgraded:
  libc-bin libc-dev-bin libc6-dev
3 upgraded, 1 newly installed, 0 to remove and 131 not upgraded.
2 not fully installed or removed.
Need to get 0 B/3331 kB of archives.
After this operation, 44.0 kB disk space will be freed.
Do you want to continue? [Y/n]
Setting up libc6:amd64 (2.31-0ubuntu5) ...
Checking for services that may need to be restarted...
Checking init scripts...
Nothing to restart.
sleep: cannot read realtime clock: Invalid argument
dpkg: error processing package libc6:amd64 (--configure):
 installed libc6:amd64 package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 libc6:amd64
E: Sub-process /usr/bin/dpkg returned an error code (1)

@harryqt
Copy link

harryqt commented Mar 15, 2020

Ubuntu Focal Fossa (20.04) also broken

After this operation, 8192 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up libc6:amd64 (2.31-0ubuntu6) ...
Checking for services that may need to be restarted...
Checking init scripts...
Nothing to restart.
sleep: cannot read realtime clock: Invalid argument
dpkg: error processing package libc6:amd64 (--configure):
 installed libc6:amd64 package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 libc6:amd64
E: Sub-process /usr/bin/dpkg returned an error code (1)

@Conduitry
Copy link

I've run into this as well on Ubuntu 20.04, and I'm currently using

sudo apt-mark hold libc6

to prevent libc from being updated to the version that breaks in WSL 1.

@danyer
Copy link

danyer commented Mar 24, 2020

This breaks Ubuntu Focal also.

# uname -a
Linux [redacted] 4.4.0-18362-Microsoft #476-Microsoft Fri Nov 01 16:53:00 PST 2019 x86_64 x86_64 x86_64 GNU/Linux

# wslsys
Release Install Date: 0x5ceea999
Branch: 19h1_release
Build: 18363
Full Build: 18362.1.amd64fre.19h1_release.190318-1202
Uptime: 6d 4h 6m
Linux Release: Ubuntu Focal Fossa (development branch)
Linux Kernel: Linux 4.4.0-18362-Microsoft
Packages Count: 1367

# apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 libc-bin : Depends: libc6 (< 2.31) but 2.31-0ubuntu5 is installed
 libc-dev-bin : Depends: libc6 (< 2.31) but 2.31-0ubuntu5 is installed
 libc6-dev : Depends: libc6 (= 2.30-0ubuntu3) but 2.31-0ubuntu5 is installed
 locales : Depends: libc-bin (> 2.31) but 2.30-0ubuntu3 is installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

# apt --fix-broken install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  libc-bin libc-dev-bin libc6-dev libcrypt-dev
Suggested packages:
  glibc-doc
The following NEW packages will be installed:
  libcrypt-dev
The following packages will be upgraded:
  libc-bin libc-dev-bin libc6-dev
3 upgraded, 1 newly installed, 0 to remove and 131 not upgraded.
2 not fully installed or removed.
Need to get 0 B/3331 kB of archives.
After this operation, 44.0 kB disk space will be freed.
Do you want to continue? [Y/n]
Setting up libc6:amd64 (2.31-0ubuntu5) ...
Checking for services that may need to be restarted...
Checking init scripts...
Nothing to restart.
sleep: cannot read realtime clock: Invalid argument
dpkg: error processing package libc6:amd64 (--configure):
 installed libc6:amd64 package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 libc6:amd64
E: Sub-process /usr/bin/dpkg returned an error code (1)

I "fixed" it somehow on my install. Because the error is in the postinstall script of libc6 package, I simply edited /var/lib/dpkg/info/libc6:amd64.postinst and transformed "sleep 1" in "echo sleep 1".
Then I run, as advised, 'apt --fix-broken install' and it managed to fix the dependencies. I removed then my change to the postinstall script. "apt update" and "apt full-upgrade" seems to be working fine after that.

Of course this is not a fix and I think I did it worse: all calls to sleep will fail. But it was fun and Ubuntu WSL1 is not my main driver so I had nothing to lose ;)

@kailiu42
Copy link

Will this be fixed for WSL1 or we can only count on WSL2?

@harryqt
Copy link

harryqt commented Mar 24, 2020

The latest build of Ubuntu 20.04 seems to be working fine without any issue in WSL1.

@SvenGroot
Copy link
Member

@Kraml A fix is coming to WSL1, and we're looking into backporting it to currently released Windows versions.

@escape0707
Copy link

escape0707 commented Jul 17, 2020

Just for reference, here's what I did on Arch WSL to downgrade glibc for now.

I was getting horrendous CPU usage in VSCode's remote WSL due to sleep not working beforehand.

wget 'https://archive.archlinux.org/packages/g/glibc/glibc-2.30-3-x86_64.pkg.tar.xz'
pacman -U glibc-2.30-3-x86_64.pkg.tar.xz

Then in /etc/pacman.conf:

HoldPkg     = glibc

Simply do:

pacman -U https://archive.archlinux.org/packages/g/glibc/glibc-2.30-3-x86_64.pkg.tar.xz

... as it will let pacman also automatically download the package's detached .sig file and verify it according to /etc/pacman.conf settings.

And do you mean IgnorePkg = glibc ?

P.S. There should also be a default value fakeroot put by its side.

@Kynolin
Copy link

Kynolin commented Jul 18, 2020

Do you mean IgnorePkg = glibc ?

P.S. There should also be a default value fakeroot put by its side.

I think I glanced at the wrong line when I added my comment, but I can't remember which was one already in there. Here's what those lines are currently set to in my pacman.conf. I updated my original comment to clarify. Thanks.

HoldPkg     = pacman glibc
IgnorePkg   = fakeroot glibc

@knoxcard2
Copy link

knoxcard2 commented Jul 21, 2020

I ran into the same problem, and this procedure from this bug report fixed it:

Edit /var/lib/dpkg/info/libc6\:amd64.postinst

and comment out the line

# set -e

so $ apt-get -f install can continue.

https://stackoverflow.com/questions/60944370/stuck-with-apt-fix-broken-install-libc6amd64-package-post-installation

@jomariaseron
Copy link

jomariaseron commented Aug 2, 2020

how can i fix the bug of sleep cannot read real time clock invalid argument? im using the latest version of ubuntu .

i then tried apt --fix-broken install but then Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied) showed up! , please help how to fix this

@juliomaranhao
Copy link

how can i fix the bug of sleep cannot read real time clock invalid argument? im using the latest version of ubuntu .

i then tried apt --fix-broken install but then Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied) showed up! , please help how to fix this

I am using this solution #4898 (comment) for a month. No trouble and much easier/secure.

@jiucenglou
Copy link

jiucenglou commented Aug 4, 2020

I prefer this solution, it seems less invasive than installing a patched glibc.

Create this file called nanosleep.c

#include <time.h>
#include <unistd.h>
# gcc -shared -fPIC -o /usr/local/lib/libnanosleep.so nanosleep.c
# echo /usr/local/lib/libnanosleep.so >> /etc/ld.so.preload

I verified this fixes sleep and htop for me.

Could you suggest how to solve the compile errors under WSL1 Ubuntu 20.04 shown below ?
(WSL1 Ubuntu 20.04 has been fixed according to https://discourse.ubuntu.com/t/ubuntu-20-04-and-wsl-1/15291/3 )

$ sudo gcc -shared -fPIC -o /usr/local/lib/libnanosleep.so nanosleep.c
nanosleep.c:1:10: fatal error: time.h: No such file or directory
    1 | #include <time.h>
      |          ^~~~~~~~
compilation terminated.

If the includes are changed to

#include <linux/time.h>
#include <linux/unistd.h>

, then the error becomes

$ sudo gcc -shared -fPIC -o /usr/local/lib/libnanosleep.so nanosleep.c
nanosleep.c: In function ‘nanosleep’:
nanosleep.c:15:12: warning: implicit declaration of function ‘clock_nanosleep’ [-Wimplicit-function-declaration]
   15 |     return clock_nanosleep(CLOCK_MONOTONIC, 0, req, rem);
      |            ^~~~~~~~~~~~~~~
nanosleep.c: At top level:
nanosleep.c:18:12: error: unknown type name ‘useconds_t’
   18 | int usleep(useconds_t usec)
      |

The search list is shown below

$ LC_ALL=C gcc -v -xc -E /dev/null 2>&1 |      sed -ne '/search starts here/,/End of search list/p'
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/9/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.

@SuperSandro2000
Copy link

@jiucenglou so you have libc6-dev installed?

@juliomaranhao
Copy link

@jiucenglou If you want to compile some C or C++, them install at least the "build-essential" ubuntu/debian meta package. Save this hint in your knowledge base.

build-essential is sufficient to compile nanosleep.c tiny C code.

$ sudo apt-cache policy build-essential
build-essential:
  Installed: 12.8ubuntu1
  Candidate: 12.8ubuntu1
  Version table:
 *** 12.8ubuntu1 500
        500 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages
        100 /var/lib/dpkg/status

@jiucenglou
Copy link

@SuperSandro2000 @juliomaranhao Many thanks ! I failed to install build-essential because sleep was broken. The problem was then solved by using another fresh Ubuntu 20.04 instance.

@hzhangxyz
Copy link

hzhangxyz commented Aug 8, 2020 via email

@hellohackie
Copy link

This breaks Ubuntu Focal also.

# uname -a
Linux [redacted] 4.4.0-18362-Microsoft #476-Microsoft Fri Nov 01 16:53:00 PST 2019 x86_64 x86_64 x86_64 GNU/Linux

# wslsys
Release Install Date: 0x5ceea999
Branch: 19h1_release
Build: 18363
Full Build: 18362.1.amd64fre.19h1_release.190318-1202
Uptime: 6d 4h 6m
Linux Release: Ubuntu Focal Fossa (development branch)
Linux Kernel: Linux 4.4.0-18362-Microsoft
Packages Count: 1367

# apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 libc-bin : Depends: libc6 (< 2.31) but 2.31-0ubuntu5 is installed
 libc-dev-bin : Depends: libc6 (< 2.31) but 2.31-0ubuntu5 is installed
 libc6-dev : Depends: libc6 (= 2.30-0ubuntu3) but 2.31-0ubuntu5 is installed
 locales : Depends: libc-bin (> 2.31) but 2.30-0ubuntu3 is installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

# apt --fix-broken install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  libc-bin libc-dev-bin libc6-dev libcrypt-dev
Suggested packages:
  glibc-doc
The following NEW packages will be installed:
  libcrypt-dev
The following packages will be upgraded:
  libc-bin libc-dev-bin libc6-dev
3 upgraded, 1 newly installed, 0 to remove and 131 not upgraded.
2 not fully installed or removed.
Need to get 0 B/3331 kB of archives.
After this operation, 44.0 kB disk space will be freed.
Do you want to continue? [Y/n]
Setting up libc6:amd64 (2.31-0ubuntu5) ...
Checking for services that may need to be restarted...
Checking init scripts...
Nothing to restart.
sleep: cannot read realtime clock: Invalid argument
dpkg: error processing package libc6:amd64 (--configure):
 installed libc6:amd64 package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 libc6:amd64
E: Sub-process /usr/bin/dpkg returned an error code (1)

I "fixed" it somehow on my install. Because the error is in the postinstall script of libc6 package, I simply edited /var/lib/dpkg/info/libc6:amd64.postinst and transformed "sleep 1" in "echo sleep 1".
Then I run, as advised, 'apt --fix-broken install' and it managed to fix the dependencies. I removed then my change to the post-install script. "apt update" and "apt full-upgrade" seems to be working fine after that.

Of course this is not a fix and I think I did it worse: all calls to sleep will fail. But it was fun and Ubuntu WSL1 is not my main driver so I had nothing to lose ;)

Worked fine but it stops package manager to upgrade 3 packages to their previous state. But glad it worked...

@CaliforniaMountainSnake

I have this problem on Ubuntu 20.04 from windows store, but not on Ubuntu 18.04. Debian also works fine.

@escape0707
Copy link

mask your glibc version for package manager, keep it in version 2.30. it's different in different distribution, for Arch Linux, add glibc to IgnorePkg in /etc/pacman.conf, I don't know whether this will cause some version confliction, but for Arch Linux, nothing crash till today.

This is actually causing two problems on ArchWSL for me now:

The first is this old glibc blocks libxcrypt update. Because libxcrypt owns /usr/include/crypt.h /usr/lib/libcrypt.so now.
The second is that when I'm still on old glibc and didn't do any update, I can no longer use vscode-python renaming.

@enihcam
Copy link

enihcam commented Aug 23, 2020

I got the following error:
ps: /usr/lib/libc.so.6: version 'GLIBC_2.32' not found (required by /usr/lib/libsystemd.so.0)

Any suggestions?

@escape0707
Copy link

escape0707 commented Aug 23, 2020 via email

@klikevil
Copy link

This also effects Kali, any chance you will have this fixed anytime soon?

 lsb_release -a
No LSB modules are available.
Distributor ID:	Kali
Description:	Kali GNU/Linux Rolling
Release:	2020.2
Codename:	kali-rolling


$ sudo apt-cache madison libc6 libc-bin
     libc6 |     2.31-2 | http://http.kali.org/kali kali-rolling/main amd64 Packages
     glibc |     2.31-2 | http://http.kali.org/kali kali-rolling/main Sources
  libc-bin |     2.31-2 | http://http.kali.org/kali kali-rolling/main amd64 Packages
     glibc |     2.31-2 | http://http.kali.org/kali kali-rolling/main Sourc

$ sudo aptitude upgrade libc-bin
Resolving dependencies...                
The following NEW packages will be installed:
  libpython3.8-minimal{a} libpython3.8-stdlib{a} python3.8{a} python3.8-minimal{a} 
The following packages will be upgraded:
  libc-bin libpython3-stdlib python3 python3-coverage python3-minimal python3-psutil 
The following partially installed packages will be configured:
  libc-dev-bin libc6 libc6-dbg libc6-dev libc6-i386 libcbor0 libfido2-1 openssh-client openssh-server openssh-sftp-server 
6 packages upgraded, 4 newly installed, 0 to remove and 634 not upgraded.
Need to get 0 B/6,020 kB of archives. After unpacking 19.0 MB will be used.
Do you want to continue? [Y/n/?] y
Setting up libc6:amd64 (2.31-2) ...      
Checking for services that may need to be restarted...
Checking init scripts...

Restarting services possibly affected by the upgrade:
  sendmail: restarting...done.

Services restarted successfully.
sleep: cannot read realtime clock: Invalid argument
dpkg: error processing package libc6:amd64 (--configure):
 installed libc6:amd64 package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 libc6:amd64
E: Sub-process /usr/bin/dpkg returned an error code (1)
Setting up libc6:amd64 (2.31-2) ...
Checking for services that may need to be restarted...
Checking init scripts...

Restarting services possibly affected by the upgrade:
  sendmail: restarting...done.

Services restarted successfully.
sleep: cannot read realtime clock: Invalid argument
dpkg: error processing package libc6:amd64 (--configure):
 installed libc6:amd64 package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of libc6-i386:
 libc6-i386 depends on libc6 (= 2.31-2); however:
  Package libc6:amd64 is not configured yet.

dpkg: error processing package libc6-i386 (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of libc6-dev:amd64:
 libc6-dev:amd64 depends on libc6 (= 2.31-2); however:
  Package libc6:amd64 is not configured yet.

dpkg: error processing package libc6-dev:amd64 (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of libfido2-1:amd64:
 libfido2-1:amd64 depends on libc6 (>= 2.25); however:
  Package libc6:amd64 is not configured yet.

dpkg: error processing package libfido2-1:amd64 (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of libc-dev-bin:
 libc-dev-bin depends on libc6 (>> 2.31); however:
  Package libc6:amd64 is not configured yet.
 libc-dev-bin depends on libc6 (<< 2.32); however:
  Package libc6:amd64 is not configured yet.

dpkg: error processing package libc-dev-bin (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of openssh-sftp-server:
 openssh-sftp-server depends on libc6 (>= 2.26); however:
  Package libc6:amd64 is not configured yet.

dpkg: error processing package openssh-sftp-server (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of openssh-server:
 openssh-server depends on openssh-sftp-server; however:
  Package openssh-sftp-server is not configured yet.
 openssh-server depends on libc6 (>= 2.26); however:
  Package libc6:amd64 is not configured yet.

dpkg: error processing package openssh-server (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of openssh-client:
 openssh-client depends on libc6 (>= 2.26); however:
  Package libc6:amd64 is not configured yet.
 openssh-client depends on libfido2-1 (>= 1.3.0); however:
  Package libfido2-1:amd64 is not configured yet.

dpkg: error processing package openssh-client (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of libcbor0:amd64:
 libcbor0:amd64 depends on libc6 (>= 2.14); however:
  Package libc6:amd64 is not configured yet.

dpkg: error processing package libcbor0:amd64 (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of libc6-dbg:amd64:
 libc6-dbg:amd64 depends on libc6 (= 2.31-2); however:
  Package libc6:amd64 is not configured yet.

dpkg: error processing package libc6-dbg:amd64 (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent processing triggers for libc-bin:
 libc-bin depends on libc6 (>> 2.29); however:
  Package libc6:amd64 is not configured yet.
 libc-bin depends on libc6 (<< 2.30); however:
  Version of libc6:amd64 on system is 2.31-2.

dpkg: error processing package libc-bin (--configure):
 dependency problems - leaving triggers unprocessed
dpkg: dependency problems prevent processing triggers for systemd:
 systemd depends on libc6 (>= 2.28); however:
  Package libc6:amd64 is not configured yet.

dpkg: error processing package systemd (--configure):
 dependency problems - leaving triggers unprocessed
dpkg: dependency problems prevent processing triggers for man-db:
 man-db depends on libc6 (>= 2.28); however:
  Package libc6:amd64 is not configured yet.

dpkg: error processing package man-db (--configure):
 dependency problems - leaving triggers unprocessed
dpkg: dependency problems prevent processing triggers for desktop-file-utils:
 desktop-file-utils depends on libc6 (>= 2.7); however:
  Package libc6:amd64 is not configured yet.

dpkg: error processing package desktop-file-utils (--configure):
 dependency problems - leaving triggers unprocessed
Errors were encountered while processing:
 libc6:amd64
 libc6-i386
 libc6-dev:amd64
 libfido2-1:amd64
 libc-dev-bin
 openssh-sftp-server
 openssh-server
 openssh-client
 libcbor0:amd64
 libc6-dbg:amd64
 libc-bin
 systemd
 man-db
 desktop-file-utils

@klikevil
Copy link

klikevil commented Aug 26, 2020

This breaks Ubuntu Focal also.

# uname -a
Linux [redacted] 4.4.0-18362-Microsoft #476-Microsoft Fri Nov 01 16:53:00 PST 2019 x86_64 x86_64 x86_64 GNU/Linux

# wslsys
Release Install Date: 0x5ceea999
Branch: 19h1_release
Build: 18363
Full Build: 18362.1.amd64fre.19h1_release.190318-1202
Uptime: 6d 4h 6m
Linux Release: Ubuntu Focal Fossa (development branch)
Linux Kernel: Linux 4.4.0-18362-Microsoft
Packages Count: 1367

# apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 libc-bin : Depends: libc6 (< 2.31) but 2.31-0ubuntu5 is installed
 libc-dev-bin : Depends: libc6 (< 2.31) but 2.31-0ubuntu5 is installed
 libc6-dev : Depends: libc6 (= 2.30-0ubuntu3) but 2.31-0ubuntu5 is installed
 locales : Depends: libc-bin (> 2.31) but 2.30-0ubuntu3 is installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

# apt --fix-broken install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
  libc-bin libc-dev-bin libc6-dev libcrypt-dev
Suggested packages:
  glibc-doc
The following NEW packages will be installed:
  libcrypt-dev
The following packages will be upgraded:
  libc-bin libc-dev-bin libc6-dev
3 upgraded, 1 newly installed, 0 to remove and 131 not upgraded.
2 not fully installed or removed.
Need to get 0 B/3331 kB of archives.
After this operation, 44.0 kB disk space will be freed.
Do you want to continue? [Y/n]
Setting up libc6:amd64 (2.31-0ubuntu5) ...
Checking for services that may need to be restarted...
Checking init scripts...
Nothing to restart.
sleep: cannot read realtime clock: Invalid argument
dpkg: error processing package libc6:amd64 (--configure):
 installed libc6:amd64 package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 libc6:amd64
E: Sub-process /usr/bin/dpkg returned an error code (1)

I "fixed" it somehow on my install. Because the error is in the postinstall script of libc6 package, I simply edited /var/lib/dpkg/info/libc6:amd64.postinst and transformed "sleep 1" in "echo sleep 1".
Then I run, as advised, 'apt --fix-broken install' and it managed to fix the dependencies. I removed then my change to the post-install script. "apt update" and "apt full-upgrade" seems to be working fine after that.
Of course this is not a fix and I think I did it worse: all calls to sleep will fail. But it was fun and Ubuntu WSL1 is not my main driver so I had nothing to lose ;)

Worked fine but it stops package manager to upgrade 3 packages to their previous state. But glad it worked...

@hellohackie : Thanks for your workaround, now let me expand on that.. You can work around this even more by installing busybox-static and using:

alias sleep='busybox sleep '

Observe:

$ strace -s 4096 -t -ff busybox sleep 3s
03:50:16 execve("/usr/bin/busybox", ["busybox", "sleep", "3s"], 0x7ffff0586030 /* 41 vars */) = 0
03:50:17 brk(NULL)                      = 0x1384000
03:50:17 brk(0x1385200)                 = 0x1385200
03:50:17 arch_prctl(ARCH_SET_FS, 0x13848c0) = 0
03:50:17 uname({sysname="Linux", nodename="D5DZ5WT2", ...}) = 0
03:50:17 readlink("/proc/self/exe", "/usr/bin/busybox", 4096) = 16
03:50:17 brk(0x13a6200)                 = 0x13a6200
03:50:17 brk(0x13a7000)                 = 0x13a7000
03:50:17 prctl(PR_SET_NAME, "busybox")  = 0
03:50:17 getuid()                       = 1000
03:50:17 stat("/etc/busybox.conf", 0x7fffc7fe3998) = -1 ENOENT (No such file or directory)
03:50:17 getgid()                       = 1000
03:50:17 setgid(1000)                   = 0
03:50:17 setuid(1000)                   = 0
03:50:17 nanosleep({tv_sec=3, tv_nsec=0}, 0x7fffc7fe3a58) = 0
03:50:20 exit_group(0)                  = ?
03:50:20 +++ exited with 0 +++

$ date;sleep 3;date
Wed 26 Aug 2020 03:51:45 AM EDT
Wed 26 Aug 2020 03:51:48 AM EDT
$ /usr/lib/x86_64-linux-gnu/libc.so.6
GNU C Library (Debian GLIBC 2.31-2) stable release version 2.31.
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 10.1.0.
libc ABIs: UNIQUE IFUNC ABSOLUTE
For bug reporting instructions, please see:
<http://www.debian.org/Bugs/>.

@TanguyOrtegat
Copy link

I prefer this solution, it seems less invasive than installing a patched glibc.

Create this file called nanosleep.c

#include <time.h>
#include <unistd.h>

// This restores the old behaviour of nanosleep() to use CLOCK_MONOTONIC.
//
// "POSIX.1 specifies that nanosleep() should measure time against the
// CLOCK_REALTIME clock. However, Linux measures the time using the
// CLOCK_MONOTONIC clock.  This probably does not matter [...]"
//
// # gcc -shared -fPIC -o /usr/local/lib/libnanosleep.so nanosleep.c
// # echo /usr/local/lib/libnanosleep.so >> /etc/ld.so.preload
//
int nanosleep(const struct timespec *req, struct timespec *rem)
{
    return clock_nanosleep(CLOCK_MONOTONIC, 0, req, rem);
}

int usleep(useconds_t usec)
{
    struct timespec req = {
        .tv_sec     = (usec / 1000000),
        .tv_nsec    = (usec % 1000000) * 1000,
    };
    return nanosleep(&req, NULL);
}
# gcc -shared -fPIC -o /usr/local/lib/libnanosleep.so nanosleep.c
# echo /usr/local/lib/libnanosleep.so >> /etc/ld.so.preload

I verified this fixes sleep and htop for me.

last line didn't work for me, but changing the command a bit, and worked!
here it is:

sudo sh -c "echo /usr/local/lib/libnanosleep.so >> /etc/ld.so.preload"

@blackadar
Copy link

This issue is fixed for Insiders in the Beta channel and the Release Preview channel with 20H2 Build 19042.487 (KB4571744). I would recommend reversing any custom changes to your WSL once you've updated.

@microsoft microsoft locked and limited conversation to collaborators Aug 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests