korlibs-archive / korio

Korio: Kotlin cORoutines I/O : Virtual File System + Async/Sync Streams + Async TCP Client/Server + WebSockets for Multiplatform Kotlin 1.3

Home Page:https://korlibs.soywiz.com/korio/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

compress crashes on iOS when run in a coroutine

1gravity opened this issue · comments

Calling ByteArray.compress(CompressionMethod) crashes on iOS due to mutable shared state:

kotlin.native.IncorrectDereferenceException: Trying to access top level value not marked as @ThreadLocal or @SharedImmutable from non-main thread
    at 0   shared                              0x0000000108788461 kfun:kotlin.Throwable#<init>(kotlin.String?){} + 97 (/Users/teamcity2/buildAgent/work/c75bfccfe067806/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Throwable.kt:24:56)
    at 1   shared                              0x000000010878159d kfun:kotlin.Exception#<init>(kotlin.String?){} + 93 (/Users/teamcity2/buildAgent/work/c75bfccfe067806/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:23:58)
    at 2   shared                              0x00000001087817bd kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 93 (/Users/teamcity2/buildAgent/work/c75bfccfe067806/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:34:58)
    at 3   shared                              0x00000001087b994d kfun:kotlin.native.IncorrectDereferenceException#<init>(kotlin.String){} + 93 (/Users/teamcity2/buildAgent/work/c75bfccfe067806/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/native/Runtime.kt:34:50)
    at 4   shared                              0x00000001087e1d63 ThrowIncorrectDereferenceException + 131 (/Users/teamcity2/buildAgent/work/c75bfccfe067806/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt:105:11)
    at 5   shared                              0x000000010899fd1e CheckGlobalsAccessible + 30
    at 6   shared                              0x0000000108b72ea3 kfun:com.soywiz.korio.internal#<get-smallBytesPool>(){}com.soywiz.kds.Pool<kotlin.ByteArray> + 195 (/Users/runner/work/korge-next/korge-next/korio/src/commonMain/kotlin/com/soywiz/korio/internal/TempBytes.kt:13:88)
    at 7   shared                              0x0000000108bd0732 kfun:com.soywiz.korio.stream.AsyncOutputStream.$writeCOROUTINE$350#invokeSuspend(kotlin.Result<kotlin.Any?>){}kotlin.Any? + 674 (/Users/runner/work/korge-next/korge-next/korio/src/commonMain/kotlin/com/soywiz/korio/stream/AsyncStream.kt:40:10)
    at 8   shared                              0x0000000108bd0ce5 kfun:com.soywiz.korio.stream.AsyncOutputStream#write(kotlin.Int){} + 309 (/Users/runner/work/korge-next/korge-next/korio/src/commonMain/kotlin/com/soywiz/korio/stream/AsyncStream.kt:40:10)
    at 9   shared                              0x0000000108be56e1 kfun:com.soywiz.korio.stream#write8__at__com.soywiz.korio.stream.AsyncOutputStream(kotlin.Int){} + 225 (/Users/runner/work/korge-next/korge-next/korio/src/commonMain/kotlin/com/soywiz/korio/stream/AsyncStream.kt:598:54)
    at 10  shared                              0x0000000108b280ca kfun:com.soywiz.korio.compression.deflate.ZLib.$compressCOROUTINE$60#invokeSuspend(kotlin.Result<kotlin.Any?>){}kotlin.Any? + 1402 (/Users/runner/work/korge-next/korge-next/korio/src/commonMain/kotlin/com/soywiz/korio/compression/deflate/ZLib.kt:86:5)
    at 11  shared                              0x0000000108b28f90

Woops. Thanks for reporting!

Woops. Thanks for reporting!

Just to add to my report. Moving to the new Kotlin memory model solves the issue for me but not everyone wants to migrate yet since it's still a development preview (https://blog.jetbrains.com/kotlin/2021/08/try-the-new-kotlin-native-memory-manager-development-preview/)

Yeah. I want to support the old memory model until the new one is stable and it is as performant as the other or pretty close.