Kotlin / kotlinx.coroutines

Library support for Kotlin coroutines
Apache License 2.0
13.02k stars 1.85k forks source link

Do not use shaded version of byte buddy when real one is present in the classpath #1060

Closed qwwdfsad closed 4 years ago

qwwdfsad commented 5 years ago

java.lang.IllegalStateException: Error during attachment using: kotlinx.coroutines.repackaged.net.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound@38dee15 caused by java.lang.UnsatisfiedLinkError: Native Library /home/.../.sdkman/candidates/java/8.0.202-zulu/jre/lib/amd64/libattach.so already loaded in another classloader

qwwdfsad commented 5 years ago

Note that reflective lookup is not the best option, probably we should first investigate whether it is possible to achieve with a regular Bute Buddy API

elizarov commented 5 years ago

This also opens a can of worms with version compatibility.... I wonder if it is possible to "shade" native libraries, too?

qwwdfsad commented 5 years ago

I am not sure it could work. Take a closer look at the library: it is platform and JVM specific and is bundled with JDK. What should we shade in that case?

elizarov commented 5 years ago

Uh. I see. That is really bad. It is not just "already loaded" it is already loaded in a different class-loader, and we we cannot get get hold on this class-loader, then we are out of luck completely....

elizarov commented 5 years ago

Similar bytebuddy sharing conflict between mockk/mockito was solved by avoiding shading bytebuddy altogether: https://github.com/mockk/mockk/issues/15

qwwdfsad commented 5 years ago

Yes, I've seen that. But we cannot avoid shading, otherwise java -jar myApp.jar -javaagent:... won't work.

xbao commented 5 years ago

Hello, I just ran into this issue trying to use kotlinx-coroutines-debug and mockk. I've resolved it for now by compiling the debug jar without the shaded ByteBuddy and including it in my project.

I imagine using kotlinx-coroutines-debug and a mocking library is a pretty common use case. Perhaps a different kotlinx-coroutines-debug artifact could be published with the unshaded ByteBuddy? Or the normal one could be unshaded, with a fatjar artifact with the shaded ByteBuddy for the -javaagent uses?

qwwdfsad commented 5 years ago

https://github.com/raphw/byte-buddy/issues/670

Let's wait for Rafael and act accordingly