ktorio / ktor

Framework for quickly creating connected applications in Kotlin with minimal effort
https://ktor.io
Apache License 2.0
12.9k stars 1.05k forks source link

LinkageError: loader constraint violation #1744

Closed blackmo18 closed 2 years ago

blackmo18 commented 4 years ago

I think this issue is related to #783

Ktor Version 1.3.1

Ktor Engine Used server netty

JVM Version, Operating System, and Relevant Context jdk1.8.0_201 ,Linux Mint 19


I was using gradle application plugin

running gradle run while on dev it was running fine

but for the case using the distribution created after gradle build

project_dir/build/distribution when I it tried runing the application

./application_name

initial loading like creating database and redis connection instance is successful then after that the error occurred

I encountered the same issue #783


These are my dependencies:

plugins {
    java
    kotlin("jvm")
    application
}

val ktor_version = "1.3.1"
val kodein_verison = "6.5.3"
val exposedVersion = "0.22.1"
val csv_reader_version = "0.7.3"

repositories {
    mavenCentral()
    jcenter()
    maven("https://jitpack.io")
}

dependencies {
    implementation(kotlin("stdlib-jdk8"))

    //-- local jar files
    implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))

    //ktor
    implementation("io.ktor:ktor-server-netty:$ktor_version")
    implementation("io.ktor:ktor:$ktor_version")
    implementation("io.ktor:ktor-websockets:$ktor_version")
    implementation( "io.ktor:ktor-gson:$ktor_version")

    //logging
    implementation("io.github.microutils:kotlin-logging:1.6.24")
    implementation("ch.qos.logback:logback-classic:1.2.3")

    // token verification
    implementation("io.ktor:ktor-auth-jwt:$ktor_version")

    //json handlers
    implementation("com.beust:klaxon:5.0.1")

    //encryption
    implementation("com.github.simbiose:Encryption:2.0.1")
    implementation("commons-codec:commons-codec:1.14")

    //di
    implementation("org.kodein.di","kodein-di-generic-jvm",kodein_verison)

    //redis
    implementation("io.lettuce:lettuce-core:5.2.1.RELEASE")

    //database
    implementation("org.jetbrains.exposed", "exposed-core", exposedVersion)
    implementation("org.jetbrains.exposed", "exposed-dao", exposedVersion)
    implementation("org.jetbrains.exposed", "exposed-jdbc", exposedVersion)
    implementation("org.jetbrains.exposed", "exposed-java-time", exposedVersion)

    //csv reader
    implementation("com.github.doyaaaaaken:kotlin-csv-jvm:$csv_reader_version")

    implementation("com.zaxxer:HikariCP:3.4.1")
    implementation ("mysql:mysql-connector-java:8.0.11")

    //-- jasper reports
    implementation("net.sf.jasperreports", "jasperreports", "6.4.0") {
        exclude("org.olap4j", "olap4j")
    }
    implementation("com.lowagie", "itext", "2.1.7")
}

application conf

ktor {
    enviroment = dev
    deployment {
        port = 3001
        watch = ["project_root"]
    }

    application {
        modules = [
            com.my.module1,
            com.my.module2,
        ]
    }
}

stack trace:

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:97)
        at kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Static.call(CallerImpl.kt:106)
        at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:106)
        at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflection(KCallableImpl.kt:152)
        at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:110)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.callFunctionWithInjection(ApplicationEngineEnvironmentReloading.kt:380)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.executeModuleFunction(ApplicationEngineEnvironmentReloading.kt:328)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.access$executeModuleFunction(ApplicationEngineEnvironmentReloading.kt:33)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading$instantiateAndConfigureApplication$1$$special$$inlined$forEach$lambda$1.invoke(ApplicationEngineEnvironmentReloading.kt:275)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading$instantiateAndConfigureApplication$1$$special$$inlined$forEach$lambda$1.invoke(ApplicationEngineEnvironmentReloading.kt:33)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.avoidingDoubleStartupFor(ApplicationEngineEnvironmentReloading.kt:308)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.access$avoidingDoubleStartupFor(ApplicationEngineEnvironmentReloading.kt:33)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading$instantiateAndConfigureApplication$1.invoke(ApplicationEngineEnvironmentReloading.kt:274)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading$instantiateAndConfigureApplication$1.invoke(ApplicationEngineEnvironmentReloading.kt:33)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.avoidingDoubleStartup(ApplicationEngineEnvironmentReloading.kt:290)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.instantiateAndConfigureApplication(ApplicationEngineEnvironmentReloading.kt:272)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.createApplication(ApplicationEngineEnvironmentReloading.kt:125)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.start(ApplicationEngineEnvironmentReloading.kt:245)
        at io.ktor.server.netty.NettyApplicationEngine.start(NettyApplicationEngine.kt:126)
        at io.ktor.server.netty.EngineMain.main(EngineMain.kt:26)
        at com.vhl.sms.caster.MainAppKt.main(MainApp.kt:47)
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:112)
        at io.ktor.websocket.WebSockets$Feature.install(WebSockets.kt:104)
        at io.ktor.application.ApplicationFeatureKt.install(ApplicationFeature.kt:64)
        at com.vhl.sms.caster.MainAppKt$messageModule$1.invokeSuspend(MainApp.kt:105)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
        at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:271)
        at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:79)
        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:54)
        at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:36)
        at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
        at com.vhl.sms.caster.MainAppKt.messageModule(MainApp.kt:57)
        ... 25 more
igr commented 4 years ago

I tried to change KTOR_ENV and disable watch, but have the same issue.

This is a showstopper :(

oleg-larshin commented 4 years ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

Stexxe commented 3 years ago

@blackmo18 could you please share your code for the modules to reproduce this problem?

Stexxe commented 2 years ago

Can't reproduce.