-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
Error loading shared library libresolv.so.2 on Alpine in Go 1.20 #59305
Comments
As of 1.20, you're responsible for linking against C libraries properly if you build with CGo enabled. Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only. For questions please refer to https://github.com/golang/go/wiki/Questions |
@bep Can you show us how to recreate the problem? Right now I don't understand it, and I don't see any clear reproduction instructions in the earlier issues. Thanks. |
@seankhliao That I understand, but this is a C library that the Go standard library (this repo) is linking, I assume to do DNS lookups. @ianlancetaylor I will put on my list and try to reproduce this in a simpler setup, but as this involves thinkering with Docker (not my favourite), it may take a few days. But please don't close this issue prematurely. |
You can see that minikube v1.30.0 suffers from this problem. |
@Nuru Is it possible that you are building with glibc and then running in a container that uses Alpine? |
@ianlancetaylor I am not building |
@Nuru Is it possible that the binary that they distribute was built with glibc, but that you are running it in a container that uses Alpine? |
The main difference is that due to the change above (in 1.20), there is now a new $ go version ./minikube-1.29.0
./minikube-1.29.0: go1.19.5
$ ldd minikube-1.29.0
linux-vdso.so.1 (0x00007ffcdc5f7000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f312da7d000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f312da5a000)
/lib64/ld-linux-x86-64.so.2 (0x00007f312dc86000)
$ go version ./minikube-1.30.0
./minikube-1.30.0: go1.20.2
$ ldd minikube-1.30.0
linux-vdso.so.1 (0x00007ffc583db000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f40eb1b2000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f40eb18f000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f40eb173000)
/lib64/ld-linux-x86-64.so.2 (0x00007f40eb3bb000) The glibc compatibility in Alpine ( |
That's exactly it @ianlancetaylor. We have a "smoke test" now failing with this issue where we build a simple hello world HTTP API using the default Something like: FROM golang:1.20 AS build
WORKDIR /app
COPY . .
RUN go build -o program .
FROM alpine
COPY --from=build /app/program .
RUN ./program See the output we now get when starting it:
So we are basically saying that starting from go1.20, the portability we used to have between glibc-based compilations, and musl-based ones, is no longer possible out of the box, without directly compiling with a "musl-gcc". |
If you want a "real" alpine binary (instead of troubleshooting the glibc compatibility), you can build with * You do need to install the For minikube we didn't want to ship double (or static) binaries, but maybe someone else want dynamic musl binaries ? $ CC=musl-gcc make
$ musl-ldd out/minikube
/lib/ld-musl-x86_64.so.1 (0x7f6b07e40000)
libc.so => /lib/ld-musl-x86_64.so.1 (0x7f6b07e40000) |
It's likely that a binary linked against glibc and dynamically linked against Alpine does not actually need a libresolv.so.2 shared library. So a workaround might be to add a dummy shared library with that name, or to link libc.so.6 to that name. |
There is a libgcompat.so library, that exports the needed symbols from the real libc. So it would be possible to fix this in the Alpine distribution, so that the default glibc compatibility layer handles this new "libresolv" like it handles "libpthread" Note that there is no
|
Thanks, that's exactly what we just did and it works. We will probably provide this answer to our users raising this specific issue from now (cross-compiling is the still in the usual "bring-your-own-toolchain" case). |
Do you have a link to the Alpine issue, about this ? I guess it would be in their interest, to be able to run go1.20 binaries |
I opened this issue with Alpine. |
apk add gcompat |
The simple answer was to upgrade to go v1.20.x from v1.15.x, but this caused a series of other problems that also needed to address so the complete list of changes and their motivations are below: 1. The upgrade to go v1.20.6 1.1. We no longer install docker-compose via pip because since v2 it ships with the main docker package itself (they rewrote it in go) 1.2. Added a new "gcompat" apk package which is necessary because of go v1.20.6 as well. Details on this can be found here: golang/go#59305 (comment) 1.3. As part of installing the OpenSSH server, we now must first wipe all openssh* packages due to newly surfaced package version conflicts due to the ones that are prepackaged with the alpine image. Without the purge step it fails like this: => ERROR [17/64] RUN apk add --no-cache openssh augeas 1.1s ------ > [17/64] RUN apk add --no-cache openssh augeas: 0.300 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/x86_64/APKINDEX.tar.gz 0.560 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/APKINDEX.tar.gz 1.041 ERROR: unable to select packages: 1.043 openssh-client-common-9.3_p1-r3: 1.043 breaks: openssh-client-default-9.3_p2-r0[openssh-client-common=9.3_p2-r0] 2. Upgraded the node-ssh library to v13 because v12 was broken due to changes introduced by the new OpenSSH server. 3. Modified the container image definition so that we have the ability to customize the version of fabric-nodeenv images used internally by the peers of the fabric-samples repository. This was needed so that we can control what version of npm and NodeJS are being used when the chain code installation process is happening (which is just the peer running the `npm install --production` command within the fabric-nodeenv container) 4. The default Fabric version used by the testing infrastructure is now Fabric v2.2.13 and for the NodeJS chain code it is 2.4.2 5. Slightly rearranged the imports & constants in some of the tests which made it easier to verify that the new image is working as intended. Fixes hyperledger-cacti#2358 Signed-off-by: Peter Somogyvari <[email protected]>
The simple answer was to upgrade to go v1.20.x from v1.15.x, but this caused a series of other problems that also needed to address so the complete list of changes and their motivations are below: 1. The upgrade to go v1.20.6 1.1. We no longer install docker-compose via pip because since v2 it ships with the main docker package itself (they rewrote it in go) 1.2. Added a new "gcompat" apk package which is necessary because of go v1.20.6 as well. Details on this can be found here: golang/go#59305 (comment) 1.3. As part of installing the OpenSSH server, we now must first wipe all openssh* packages due to newly surfaced package version conflicts due to the ones that are prepackaged with the alpine image. Without the purge step it fails like this: => ERROR [17/64] RUN apk add --no-cache openssh augeas 1.1s ------ > [17/64] RUN apk add --no-cache openssh augeas: 0.300 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/x86_64/APKINDEX.tar.gz 0.560 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/APKINDEX.tar.gz 1.041 ERROR: unable to select packages: 1.043 openssh-client-common-9.3_p1-r3: 1.043 breaks: openssh-client-default-9.3_p2-r0[openssh-client-common=9.3_p2-r0] 2. Upgraded the node-ssh library to v13 because v12 was broken due to changes introduced by the new OpenSSH server. 3. Modified the container image definition so that we have the ability to customize the version of fabric-nodeenv images used internally by the peers of the fabric-samples repository. This was needed so that we can control what version of npm and NodeJS are being used when the chain code installation process is happening (which is just the peer running the `npm install --production` command within the fabric-nodeenv container) 4. The default Fabric version used by the testing infrastructure is now Fabric v2.2.13 and for the NodeJS chain code it is 2.4.2 5. Slightly rearranged the imports & constants in some of the tests which made it easier to verify that the new image is working as intended. 6. The new image built from this dockerfile for Fabric AIO 2.x is tagged on the registry as: `ghcr.io/hyperledger/cactus-fabric2-all-in-one:2023-08-05-issue2358` Fixes hyperledger-cacti#2358 Signed-off-by: Peter Somogyvari <[email protected]>
The simple answer was to upgrade to go v1.20.x from v1.15.x, but this caused a series of other problems that also needed to address so the complete list of changes and their motivations are below: 1. The upgrade to go v1.20.6 1.1. We no longer install docker-compose via pip because since v2 it ships with the main docker package itself (they rewrote it in go) 1.2. Added a new "gcompat" apk package which is necessary because of go v1.20.6 as well. Details on this can be found here: golang/go#59305 (comment) 1.3. As part of installing the OpenSSH server, we now must first wipe all openssh* packages due to newly surfaced package version conflicts due to the ones that are prepackaged with the alpine image. Without the purge step it fails like this: => ERROR [17/64] RUN apk add --no-cache openssh augeas 1.1s ------ > [17/64] RUN apk add --no-cache openssh augeas: 0.300 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/x86_64/APKINDEX.tar.gz 0.560 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/APKINDEX.tar.gz 1.041 ERROR: unable to select packages: 1.043 openssh-client-common-9.3_p1-r3: 1.043 breaks: openssh-client-default-9.3_p2-r0[openssh-client-common=9.3_p2-r0] 2. Upgraded the node-ssh library to v13 because v12 was broken due to changes introduced by the new OpenSSH server. 3. Modified the container image definition so that we have the ability to customize the version of fabric-nodeenv images used internally by the peers of the fabric-samples repository. This was needed so that we can control what version of npm and NodeJS are being used when the chain code installation process is happening (which is just the peer running the `npm install --production` command within the fabric-nodeenv container) 4. The default Fabric version used by the testing infrastructure is now Fabric v2.2.13 and for the NodeJS chain code it is 2.4.2 5. Slightly rearranged the imports & constants in some of the tests which made it easier to verify that the new image is working as intended. 6. The new image built from this dockerfile for Fabric AIO 2.x is tagged on the registry as: `ghcr.io/hyperledger/cactus-fabric2-all-in-one:2023-08-05-issue2358` 7. increased the tap timeout from 900 seconds (15 minutes) to 3600 (an hour) Fixes hyperledger-cacti#2358 Signed-off-by: Peter Somogyvari <[email protected]>
The simple answer was to upgrade to go v1.20.x from v1.15.x, but this caused a series of other problems that also needed to address so the complete list of changes and their motivations are below: 1. The upgrade to go v1.20.6 1.1. We no longer install docker-compose via pip because since v2 it ships with the main docker package itself (they rewrote it in go) 1.2. Added a new "gcompat" apk package which is necessary because of go v1.20.6 as well. Details on this can be found here: golang/go#59305 (comment) 1.3. As part of installing the OpenSSH server, we now must first wipe all openssh* packages due to newly surfaced package version conflicts due to the ones that are prepackaged with the alpine image. Without the purge step it fails like this: => ERROR [17/64] RUN apk add --no-cache openssh augeas 1.1s ------ > [17/64] RUN apk add --no-cache openssh augeas: 0.300 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/x86_64/APKINDEX.tar.gz 0.560 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/APKINDEX.tar.gz 1.041 ERROR: unable to select packages: 1.043 openssh-client-common-9.3_p1-r3: 1.043 breaks: openssh-client-default-9.3_p2-r0[openssh-client-common=9.3_p2-r0] 2. Upgraded the node-ssh library to v13 because v12 was broken due to changes introduced by the new OpenSSH server. 3. Modified the container image definition so that we have the ability to customize the version of fabric-nodeenv images used internally by the peers of the fabric-samples repository. This was needed so that we can control what version of npm and NodeJS are being used when the chain code installation process is happening (which is just the peer running the `npm install --production` command within the fabric-nodeenv container) 4. The default Fabric version used by the testing infrastructure is now Fabric v2.2.13 and for the NodeJS chain code it is 2.4.2 5. Slightly rearranged the imports & constants in some of the tests which made it easier to verify that the new image is working as intended. 6. The new image built from this dockerfile for Fabric AIO 2.x is tagged on the registry as: `ghcr.io/hyperledger/cactus-fabric2-all-in-one:2023-08-05-issue2358` 7. increased the tap timeout from 900 seconds (15 minutes) to 3600 (an hour) Fixes #2358 Signed-off-by: Peter Somogyvari <[email protected]>
There were errors "Error loading shared library libresolv.so.2: No such file or directory (needed by /usr/share/filebeat/filebeat" which apparently is due to Alpine not including libs needed by newer Go apps. golang/go#59305 https://gitlab.alpinelinux.org/alpine/aports/-/issues/14846
I also meet this problem. After following your repair steps, it was not successful and another error message appeared:
But I compiled the program using go1.19 and then executed it successfully under alpine. |
The simple answer was to upgrade to go v1.20.x from v1.15.x, but this caused a series of other problems that also needed to address so the complete list of changes and their motivations are below: 1. The upgrade to go v1.20.6 1.1. We no longer install docker-compose via pip because since v2 it ships with the main docker package itself (they rewrote it in go) 1.2. Added a new "gcompat" apk package which is necessary because of go v1.20.6 as well. Details on this can be found here: golang/go#59305 (comment) 1.3. As part of installing the OpenSSH server, we now must first wipe all openssh* packages due to newly surfaced package version conflicts due to the ones that are prepackaged with the alpine image. Without the purge step it fails like this: => ERROR [17/64] RUN apk add --no-cache openssh augeas 1.1s ------ > [17/64] RUN apk add --no-cache openssh augeas: 0.300 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/x86_64/APKINDEX.tar.gz 0.560 fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/APKINDEX.tar.gz 1.041 ERROR: unable to select packages: 1.043 openssh-client-common-9.3_p1-r3: 1.043 breaks: openssh-client-default-9.3_p2-r0[openssh-client-common=9.3_p2-r0] 2. Upgraded the node-ssh library to v13 because v12 was broken due to changes introduced by the new OpenSSH server. 3. Modified the container image definition so that we have the ability to customize the version of fabric-nodeenv images used internally by the peers of the fabric-samples repository. This was needed so that we can control what version of npm and NodeJS are being used when the chain code installation process is happening (which is just the peer running the `npm install --production` command within the fabric-nodeenv container) 4. The default Fabric version used by the testing infrastructure is now Fabric v2.2.13 and for the NodeJS chain code it is 2.4.2 5. Slightly rearranged the imports & constants in some of the tests which made it easier to verify that the new image is working as intended. 6. The new image built from this dockerfile for Fabric AIO 2.x is tagged on the registry as: `ghcr.io/hyperledger/cactus-fabric2-all-in-one:2023-08-05-issue2358` 7. increased the tap timeout from 900 seconds (15 minutes) to 3600 (an hour) Fixes hyperledger-cacti#2358 Signed-off-by: Peter Somogyvari <[email protected]>
This is a reopening of #59304 -- which was closed with a not very helpful "working as intended" message.
Searching this GitHub repo for musl libc shows lots of existing relevant issues/code adaptations. People, like me, could maybe be lead to believe that Musl Libc was supported (and Alpine is a very popular Docker runtime). I'm not saying that this is a bug, but it's at least a documentation issue.
I understand that with the big number of issues in your back log, you need to somehow be very effective about this, but these short and cranky brush offs with "working as intended" is, I suspect, not having the effect you want in the long run.
The text was updated successfully, but these errors were encountered: