Closed Ccixyj closed 5 years ago
Could you please provide full stacktrace?
Could you please provide full stacktrace?
I have edited ,check please.
Ok, have reproduced it. Thanks
The reason why it happens is that you have a watch pattern that matches everything (empty or /
) that causes hot-reloading classloader to watch and load all the classes that causes this violation
The root cause is explained here http://frankkieviet.blogspot.com/2009/03/javalanglinkageerror-loader-constraint.html
We already have similar/related workaround in ktor: we are skipping ktor core from child classloader but org.slf4j.Logger
is not blacklisted so we have linkage error. We need to think more about possible solution.
User's workaround is to not include everything to watch list. Note that /
pattern will include everything including JDK's classes that is not right. Please specify watch patterns more precisely.
For now a temporary workaround is applied as per commit 87c71dd
Fixed in 1.1.0
Fixed in 1.1.0
this error also happend using WebSockets feature ktor version 1.1.1
Exception in thread "main" java.lang.reflect.InvocationTargetException
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:498)
at kotlin.reflect.jvm.internal.calls.CallerImpl$Method.callMethod(CallerImpl.kt:71)
at kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Static.call(CallerImpl.kt:80)
at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:106)
at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflect_api(KCallableImpl.kt:152)
at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:110)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.callFunctionWithInjection(ApplicationEngineEnvironmentReloading.kt:347)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.executeModuleFunction(ApplicationEngineEnvironmentReloading.kt:297)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.instantiateAndConfigureApplication(ApplicationEngineEnvironmentReloading.kt:273)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.createApplication(ApplicationEngineEnvironmentReloading.kt:126)
at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.start(ApplicationEngineEnvironmentReloading.kt:245)
at io.ktor.server.netty.NettyApplicationEngine.start(NettyApplicationEngine.kt:106)
at BlogAppKt.main(BlogApp.kt:99)
Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "io.ktor.application.ApplicationEvents.subscribe(Lio/ktor/application/EventDefinition;Lkotlin/jvm/functions/Function1;)Lkotlinx/coroutines/DisposableHandle;" the class loader (instance of io/ktor/server/engine/OverridingClassLoader$ChildURLClassLoader) of the current class, io/ktor/websocket/WebSockets$Feature, and the class loader (instance of sun/misc/Launcher$AppClassLoader) for the method's defining class, io/ktor/application/ApplicationEvents, have different Class objects for the type kotlinx/coroutines/DisposableHandle used in the signature
at io.ktor.websocket.WebSockets$Feature.install(WebSockets.kt:79)
at io.ktor.websocket.WebSockets$Feature.install(WebSockets.kt:71)
at io.ktor.application.ApplicationFeatureKt.install(ApplicationFeature.kt:59)
at BlogAppKt.main(BlogApp.kt:49)
... 16 more
Ran into this as well with:
java.lang.LinkageError: loader constraint violation: when resolving method "kotlinx.coroutines.io.CoroutinesKt.writer(Lkotlinx/coroutines/CoroutineScope;Lkotlin/coroutines/CoroutineContext;Lkotlinx/coroutines/io/ByteChannel;Lkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/io/WriterJob;" the class loader (instance of io/ktor/server/engine/OverridingClassLoader$ChildURLClassLoader) of the current class, io/ktor/network/sockets/CIOReaderKt, and the class loader (instance of sun/misc/Launcher$AppClassLoader) for the method's defining class, kotlinx/coroutines/io/CoroutinesKt, have different Class objects for the type kotlinx/coroutines/CoroutineScope used in the signature
BTW, I resolved this by not setting the watchPaths
when creating the embeddedServer
.
I faced this issue when deploying ktor server to digitalocean droplet using dokku had to disable development mode from application.conf and then it worked
Ktor Version
1.0.1
Ktor Engine Used(client or server and name)
server netty
JVM Version, Operating System and Relevant Context
jdk1.8.0_181 ,windows
Feedback
code based on ktor-samples/feature/testable:
add main function
request "localhost:8080" cause this error
remove
watchPaths
ortrace { application.log.info(it.buildText()) }
is okstacktrace: