kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlinx.coroutines.StandaloneCoroutine@28a82d8
See original GitHub issueworks on android, breaks on ios
code:
fun triggerNetworkCall(){
GlobalScope.apply {
launch(Background) {
try {
val data = repository.getSettings()
} catch (t: Throwable) {
Logger.d("ktor", t.message?:"null")
}
}
}
}
suspend fun getSettings(): String? {
val response = apiConfig.getReferralData()
return response
}
suspend fun getReferralData(): String? {
val localClient = HttpClient(PlatformHttpClient.httpClientEngine){
install(JsonFeature)
}
return localClient.post {
url {
protocol = URLProtocol.HTTPS
host = "postman-echo.com"
encodedPath = "post"
}
contentType(ContentType.Application.Json)
body = "{}"
HttpMethod.Post
}
}
This post request works in android but fails in iOS with following stack trace:
Uncaught Kotlin exception: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlinx.coroutines.StandaloneCoroutine@1a8b4e8
whereas a get request works on both platforms. Following is the function being used:
suspend fun getReferralData(): String? {
val localClient = HttpClient(PlatformHttpClient.httpClientEngine){
install(JsonFeature)
}
val address = Url("https://postman-echo.com/get?foo1=bar1&foo2=bar2")
return localClient.get {
url {
url(address.toString())
}
}
}
Dispatchers definition: iOS
internal actual val Main: CoroutineDispatcher = NsQueueDispatcher(dispatch_get_main_queue())
internal actual val Background: CoroutineDispatcher = Main
internal class NsQueueDispatcher(
private val dispatchQueue: dispatch_queue_t
) : CoroutineDispatcher() {
override fun dispatch(context: CoroutineContext, block: Runnable) {
dispatch_async(dispatchQueue) {
block.run()
}
}
}
android
internal actual val Main: CoroutineDispatcher = Dispatchers.Main
internal actual val Background: CoroutineDispatcher = Dispatchers.Default
dependencies
commonMain {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-common:1.3.61"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.14.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.2-1.3.60"
implementation "co.touchlab:stately:0.9.4"
implementation "co.touchlab:stately-collections:0.9.4"
implementation "io.ktor:ktor-client-core:1.2.6"
implementation "io.ktor:ktor-client-json:1.2.6"
implementation "io.ktor:ktor-client-logging:1.2.6"
implementation "io.ktor:ktor-client-serialization:1.2.6"
implementation "com.github.aakira:napier:1.1.0"
}
}
androidMain {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.3.61"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.14.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2-1.3.60"
implementation "io.ktor:ktor-client-core-jvm:1.2.6"
implementation "io.ktor:ktor-client-json-jvm:1.2.6"
implementation "io.ktor:ktor-client-logging-jvm:1.2.6"
implementation "io.ktor:ktor-client-serialization-jvm:1.2.6"
implementation "io.ktor:ktor-client-android:1.2.6"
implementation "com.github.aakira:napier-android:1.1.0"
}
}
iosMain {
dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:0.14.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:1.3.2-1.3.60"
implementation "io.ktor:ktor-client-core-native:1.2.6"
implementation "io.ktor:ktor-client-json-native:1.2.6"
implementation "io.ktor:ktor-client-logging-native:1.2.6"
implementation "io.ktor:ktor-client-serialization-native:1.2.6"
implementation "io.ktor:ktor-client-ios:1.2.6"
implementation "com.github.aakira:napier-ios:1.1.0"
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:23 (2 by maintainers)
Top Results From Across the Web
kotlin.native.concurrent.InvalidMutabilityException - YouTrack
I am trying to upload an image as multiform data using KMM. For android, it's working fine, and able to upload it. But...
Read more >kotlin.native.concurrent.InvalidMutabilityException: mutation ...
I find an issue filed here https://github.com/Kotlin/kotlinx.serialization/issues/1450. I tried one of the workaround i.e. ...
Read more >InvalidMutabilityException - Kotlin Programming Language
Exception thrown whenever we attempt to mutate frozen objects. Parameters. where - a frozen object that was attempted to mutate. Constructors. Native.
Read more >kotlin.native.concurrent.InvalidMutabilityException
kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlinx.coroutines.StandaloneCoroutine@28a82d8.
Read more >The weird and wonderful world of threading in Kotlin-Native
kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen com.example.project.MyClass@fe10a8.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This issue happens on version 1.4.0 while on 1.3.2-1.4.0-rc everything works fine.
@joaquim-verges I solve it.