Looks as though the Ktor KotlinX Serialisation lib...
# ktor
n
Looks as though the Ktor KotlinX Serialisation library is causing a InvalidMutablityException to be thrown.
1
Below is the stack trace:
Copy code
Uncaught Kotlin exception: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlin.collections.HashMap@15e4e58
        at kfun:kotlin.Throwable.<init>(kotlin.String?)kotlin.Throwable (0x2f8907)
        at kfun:kotlin.Exception.<init>(kotlin.String?)kotlin.Exception (0x2f2215)
        at kfun:kotlin.RuntimeException.<init>(kotlin.String?)kotlin.RuntimeException (0x2f1dd5)
        at kfun:kotlin.native.concurrent.InvalidMutabilityException.<init>(kotlin.String)kotlin.native.concurrent.InvalidMutabilityException (0x31ff55)
        at ThrowInvalidMutabilityException (0x321643)
        at MutationCheck (0x6489ae)
        at kfun:kotlin.collections.HashMap.<set-length>#internal (0x3034bd)
        at kfun:kotlin.collections.HashMap.addKey$stdlib(K)<http://kotlin.Int|kotlin.Int> (0x307aeb)
        at kfun:kotlin.collections.HashMap.put(K;V)V? (0x3044c9)
        at kfun:io.ktor.util.AttributesNative.put#internal (0x4e144f)
        at kfun:io.ktor.client.features.$addDefaultResponseValidation$lambda-1$lambda-0COROUTINE$18.invokeSuspend#internal (0x53bc0c)
        at kfun:io.ktor.client.features.$addDefaultResponseValidation$lambda-1$lambda-0COROUTINE$18.invoke#internal (0x53c2c2)
        at kfun:io.ktor.client.features.HttpCallValidator.$validateResponseCOROUTINE$24.invokeSuspend#internal (0x544a5c)
        at kfun:io.ktor.client.features.HttpCallValidator.validateResponse#internal (0x544d76)
        at kfun:io.ktor.client.features.HttpCallValidator.Companion.$install$lambda-1COROUTINE$23.invokeSuspend#internal (0x5479a0)
        at kfun:io.ktor.client.features.HttpCallValidator.Companion.$install$lambda-1COROUTINE$23.invoke#internal (0x5482ff)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal (0x4dd9cd)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.proceed#internal (0x4dd04e)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.execute#internal (0x4dd451)
        at kfun:io.ktor.util.pipeline.Pipeline.execute(TContext;TSubject)TSubject (0x4d8220)
        at kfun:io.ktor.client.call.HttpClientCall.$receiveCOROUTINE$13.invokeSuspend(kotlin.Result<kotlin.Any?>)kotlin.Any? (0x52e887)
        at kfun:io.ktor.client.call.HttpClientCall.receive(io.ktor.client.call.TypeInfo)kotlin.Any (0x52eef6)
        at kfun:com.chapman.batteryMetricsExtractor.$runCellVoltageQueryCOROUTINE$0.invokeSuspend#internal (0x5f6323)
        at kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) (0x313d98)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith#internal (0x4de098)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal (0x4ddc03)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.object-1.resumeWith#internal (0x4dfc1c)
        at kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) (0x314079)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith#internal (0x4de098)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal (0x4ddc03)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.object-1.resumeWith#internal (0x4dfc1c)
        at kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) (0x314079)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith#internal (0x4de098)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal (0x4ddc03)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.object-1.resumeWith#internal (0x4dfc1c)
        at kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) (0x314079)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith#internal (0x4de098)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal (0x4ddc03)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.object-1.resumeWith#internal (0x4dfc1c)
        at kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) (0x314079)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith#internal (0x4de098)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.loop#internal (0x4ddc03)
        at kfun:io.ktor.util.pipeline.SuspendFunctionGun.object-1.resumeWith#internal (0x4dfc1c)
        at kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) (0x314079)
        at kfun:kotlinx.coroutines.DispatchedTask.run() (0x3fb2ba)
        at kfun:kotlinx.coroutines.EventLoopImplBase.processNextEvent()kotlin.Long (0x3d6c70)
        at kfun:kotlinx.coroutines.BlockingCoroutine.joinBlocking#internal (0x4082ee)
        at kfun:kotlinx.coroutines.runBlocking(kotlin.coroutines.CoroutineContext;kotlin.coroutines.SuspendFunction1<kotlinx.coroutines.CoroutineScope,T>){0<kotlin.Any?>}Generic (0x4073d8)
        at kfun:kotlinx.coroutines.runBlocking$default(kotlin.coroutines.CoroutineContext?;kotlin.coroutines.SuspendFunction1<kotlinx.coroutines.CoroutineScope,T>;<http://kotlin.Int|kotlin.Int>){0<kotlin.Any?>}Generic (0x407911)
        at kfun:com.chapman.batteryMetricsExtractor.main(kotlin.Array<kotlin.String>) (0x5f3238)
        at Konan_start (0x5f82fb)
        at Init_and_run_start (0x62522b)
        at __libc_start_main (0x7f6c00a24b97)
        at  (0x2ad029)
        at  ((nil))

Execution failed for task ':runBatt_metrics_extractorDebugExecutableLinuxX64'
The exception masks the real problem that has occurred (the HTTP 405 error). Should I file a new issue in the issue tracker?
Fixed the problem by using the correct URL. With the JVM version it throws a different exception (Ktor's ClientRequestException) when using the incorrect URL.
c
// @e5l
e
Hi @napperley, thanks for the report. Yep, the issue would be nice
n
Unfortunately the project I am working on isn't open source, however I can provide the function definition, and its dependencies (from the common module) that will reproduce the issue:
Copy code
private const val FORM_URL_ENCODED = "application/x-www-form-urlencoded"

internal val httpClient = createHttpClient()

internal expect fun createHttpClient(): HttpClient
// ...

internal suspend fun runUpQuery(host: String, port: Int): String =
    <http://httpClient.post|httpClient.post>("http://$host:$port/") {
        contentType(ContentType.parse(FORM_URL_ENCODED))
        body = listOf("query" to "up").formUrlEncode()
    }
The following environment needs to be setup to reproduce the issue: 1. Install and configure Prometheus ( https://prometheus.io/ ) to run as a Daemon 2. Create a new Kotlin Multiplatform project with two modules (common, and linuxX64) using Kotlin 1.3.70, and Gradle 6.2.2 3. Setup a program through the linuxX64 module which uses linuxX64 as the Kotlin Native target
👀 1
🙏 1