kohlschutter / junixsocket

Unix Domain Sockets in Java 7 and newer (AF_UNIX), AF_TIPC, AF_VSOCK, and more
Apache License 2.0
438 stars 114 forks source link

Error loading shared library libstdc++.so.6 #33

Closed pierredavidbelanger closed 7 years ago

pierredavidbelanger commented 7 years ago

I am using docker-java in an application that runs inside a container, to access the host /var/run/docker.sock (mounted as /var/run/docker.sock inside the container with -v /var/run/docker.sock:/var/run/docker.sock).

I am unable to connect, here is the interesting part of the stacktrace:

app_1  | java.lang.UnsatisfiedLinkError: /tmp/libjunixsocket-native-2.0.44851090766141539397.so: Error loading shared library libstdc++.so.6: No such file or directory (needed by /tmp/libjunixsocket-native-2.0.44851090766141539397.so)
app_1  |    at java.lang.ClassLoader$NativeLibrary.load(Native Method) ~[na:1.8.0_111-internal]
app_1  |    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941) ~[na:1.8.0_111-internal]
app_1  |    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824) ~[na:1.8.0_111-internal]
app_1  |    at java.lang.Runtime.load0(Runtime.java:809) ~[na:1.8.0_111-internal]
app_1  |    at java.lang.System.load(System.java:1086) ~[na:1.8.0_111-internal]
app_1  |    at org.newsclub.net.unix.NarSystem.loadLibrary(NarSystem.java:39) ~[junixsocket-native-common-2.0.4.jar!/:na]
app_1  |    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111-internal]
app_1  |    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111-internal]
app_1  |    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111-internal]
app_1  |    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111-internal]
app_1  |    at org.newsclub.net.unix.NativeUnixSocket.<clinit>(NativeUnixSocket.java:35) ~[junixsocket-common-2.0.4.jar!/:na]
app_1  |    at org.newsclub.net.unix.AFUNIXSocket.<init>(AFUNIXSocket.java:36) ~[junixsocket-common-2.0.4.jar!/:na]
app_1  |    at org.newsclub.net.unix.AFUNIXSocket.newInstance(AFUNIXSocket.java:54) ~[junixsocket-common-2.0.4.jar!/:na]
app_1  |    at com.github.dockerjava.jaxrs.ApacheUnixSocket.<init>(ApacheUnixSocket.java:51) ~[docker-java-3.0.6.jar!/:na]
pierredavidbelanger commented 7 years ago

Ho, I am sorry, I think I know.

I guess libstdc++.so.6 is not found because my Dockerfile is FROM java:8-alpine.

I will try with an other base image and see if I still have this problem.

pierredavidbelanger commented 7 years ago

Ok, so, my problem was indeed an issue with alpine.

The fact that alpine is using musl-libc must somehow be the root cause.

My app is now working if I base my Dockerfile FROM openjdk:8.

The side-effect of this is that my image is now really bigger:

REPOSITORY                TAG                 IMAGE ID            CREATED              SIZE
new_app                   latest              xxxxxxxxxxxx        23 seconds ago       678.6 MB
app                       latest              xxxxxxxxxxxx        4 days ago           166.7 MB
pierredavidbelanger commented 7 years ago

FWIW, an other interesting way to fix this problem (and stay with alpine) is to install the libstdc++ package, like this:

FROM java:8-alpine
...
RUN apk add --no-cache libstdc++
...

At runtime, libjunixsocket-native will find what it wants:

$ ldd /tmp/libjunixsocket-native-2.0.45373916279860178862.so 
    ldd (0x56432e94b000)
    libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7fcaba3d3000)
    libm.so.6 => ldd (0x56432e94b000)
    libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7fcaba1c0000)
    libc.so.6 => ldd (0x56432e94b000)

But I do not know what other problems this fix could cause, because from what I can see, java is still linked to musl:

$ ldd /usr/bin/java
...
    /lib/ld-musl-x86_64.so.1 (0x564ed8a3f000)
...

Anyways, I will stop spamming this thread, everything is working for me now.

kohlschuetter commented 5 years ago

junixsocket 2.2.0 now ships with two separate libraries, one that links against glibc, and one that doesn't.

In other words, try with 2.2.0 on Alpine Linux with a Java runtime that uses musl, and see if you still need the libstdc++ dependency.

kohlschuetter commented 1 year ago

This page still receives a significant amount of traffic. Which means that whatever software you're using depends on a very outdated junixsocket version.

Please upgrade your junixsocket dependencies to 2.8.3 or newer. If you are unable to do so, or don't know how to do that, open a new issue with details about the environment you're seeing this error in.

Thanks for your help!