testcontainers / testcontainers-java

Testcontainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.
https://testcontainers.org
MIT License
8.05k stars 1.66k forks source link

[Bug]: Not able to use Elastic Search Transport client because of duplicate java native library "libnet.dylib" load #6798

Open sgupta0102 opened 1 year ago

sgupta0102 commented 1 year ago

Module

Elasticsearch

Testcontainers version

1.17.6

Using the latest Testcontainers version?

Yes

Host OS

Mac Os

Host Arch

aarch_64

Docker version

Docker version 20.10.23, build 7155243

What happened?

Test container is loading the java native library "libnet.dylib" on startup. If the application is using an Elastic search transport client which also tries to load the name native library and fails.

Relevant log output

[elasticsearch[_client_][transport_worker][T#1]] - [ChannelInitializer] - Failed to initialize a channel. Closing: [id: 0x314081aa] java.lang.UnsatisfiedLinkError: Native Library /Library/Java/JavaVirtualMachines/jdk1.8.0_361.jdk/Contents/Home/jre/lib/libnet.dylib already loaded in another classloader
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1903) ~[?:1.8.0_361]
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1841) ~[?:1.8.0_361]
    at java.lang.Runtime.loadLibrary0(Runtime.java:843) ~[?:1.8.0_361]
    at java.lang.System.loadLibrary(System.java:1134) ~[?:1.8.0_361]
    at jdk.net.MacOSXSocketOptions.<clinit>(MacOSXSocketOptions.java:78) ~[?:1.8.0_361]
    at java.lang.Class.forName0(Native Method) ~[?:1.8.0_361]
    at java.lang.Class.forName(Class.java:264) ~[?:1.8.0_361]
    at jdk.net.ExtendedSocketOptions$PlatformSocketOptions.newInstance(ExtendedSocketOptions.java:286) ~[?:1.8.0_361]
    at jdk.net.ExtendedSocketOptions$PlatformSocketOptions.create(ExtendedSocketOptions.java:305) ~[?:1.8.0_361]
    at jdk.net.ExtendedSocketOptions$PlatformSocketOptions.<clinit>(ExtendedSocketOptions.java:311) ~[?:1.8.0_361]
    at jdk.net.ExtendedSocketOptions.<clinit>(ExtendedSocketOptions.java:136) ~[?:1.8.0_361]
    at java.lang.Class.forName0(Native Method) ~[?:1.8.0_361]
    at java.lang.Class.forName(Class.java:264) ~[?:1.8.0_361]
    at org.elasticsearch.core.internal.net.NetUtils.getExtendedSocketOptionOrNull(NetUtils.java:47) ~[elasticsearch-core-7.17.0.jar:7.17.0]
    at org.elasticsearch.core.internal.net.NetUtils.getTcpKeepIdleSocketOptionOrNull(NetUtils.java:27) ~[elasticsearch-core-7.17.0.jar:7.17.0]
    at org.elasticsearch.core.internal.net.NetUtils.tryEnsureReasonableKeepAliveConfig(NetUtils.java:70) ~[elasticsearch-core-7.17.0.jar:7.17.0]
    at org.elasticsearch.transport.netty4.Netty4Transport$ClientChannelInitializer.initChannel(Netty4Transport.java:329) [transport-netty4-client-7.17.0.jar:7.17.0]
    at io.netty.channel.ChannelInitializer.initChannel(ChannelInitializer.java:115) [netty-transport-4.1.29.Final.jar:4.1.29.Final]
    at io.netty.channel.ChannelInitializer.handlerAdded(ChannelInitializer.java:107) [netty-transport-4.1.29.Final.jar:4.1.29.Final]

Additional Information

No response

eddumelendez commented 1 year ago

Can you share a minimal reproducer project, please?