scijava / native-lib-loader

Native library loader for extracting and loading native libraries from Java.
Other
186 stars 41 forks source link

Load hangs on busybox linux #6

Closed CodingFabian closed 8 years ago

CodingFabian commented 9 years ago

Hi, i tried running a java app which uses junixsocket in a busybox linux container. junixsocket uses your project to load its native file. the thread dump looks like this

"pool-23-thread-1" #92 prio=5 os_prio=0 tid=0x00007f5f8842c800 nid=0x9b runnable [0x00007f5f677f6000]
   java.lang.Thread.State: RUNNABLE
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1937)
    - locked <0x00000000e01efd98> (a java.util.Vector)
    - locked <0x00000000fe828f80> (a java.util.Vector)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1822)
    at java.lang.Runtime.load0(Runtime.java:809)
    - locked <0x00000000e016d580> (a java.lang.Runtime)
    at java.lang.System.load(System.java:1086)
    at org.newsclub.net.unix.NarSystem.loadLibrary(NarSystem.java:39)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.newsclub.net.unix.NativeUnixSocket.<clinit>(NativeUnixSocket.java:35)
    at org.newsclub.net.unix.AFUNIXSocket.<init>(AFUNIXSocket.java:36)
    at org.newsclub.net.unix.AFUNIXSocket.newInstance(AFUNIXSocket.java:54)

I can see that the file was extracted successfully to /tmp/libjunixsocket-native-2.0.45209276038407333080.so everything in this container runs under root and I can read the library.

Do you have any idea how to fix this? I can spend some time troubleshooting this. The base image I use is progrium/busybox

ctrueden commented 9 years ago

That's a weird one. What happens if you pre-extract the library, add it to the java.library.path at Java startup, and then use System.loadLibrary as normal? Does that work? And what happens if you pre-extract it, then use System.load without it being on java.library.path? Differences here may shed some light on where/how things are going wrong.

If it still hangs with System.loadLibrary, then perhaps this SO thread can help shed some light on it.

If it doesn't hang with System.loadLibrary, perhaps it has to do with the dependencies of the native library? Because System.load is very low level and much more "fragile" in that sense than loadLibrary is. And my understanding is that in some cases at least, you need to load the native dependency tree in reverse order for things to work properly.

CodingFabian commented 9 years ago

Thank you @ctrueden for your reply, I will experiment tomorrow and let you know if that sheds light onto this. Just a bit more info. I was able to get the very same application running using Alpine (which is an enhanced busybox) and of course centos and ubuntu. Right now it feels to me that some syscalls in busybox are misbehaving (never dug that deep in kernel code..)

ctrueden commented 8 years ago

@CodingFabian Since it sounds like this is/was likely a busybox issue, I'm closing the issue here. But please feel warmly welcome to reopen this, and/or file a new issue, if you believe native-lib-loader plays any part in the problematic behavior!