ntherning
10/22/2020, 9:17 AMSomeClass
instance in this piece of code to get frozen:
import kotlinx.coroutines.*
import kotlin.native.concurrent.*
import kotlin.test.*
class SomeClass
class UnexpectedFreezing {
@Test
fun doTest() {
val dispatcher = newSingleThreadContext("thread")
runBlocking(dispatcher) {
runCatching {
val o = withContext(dispatcher) {
SomeClass().apply { ensureNeverFrozen() }
}
assertFalse(o.isFrozen)
}.exceptionOrNull()?.printStackTrace()
}
}
}
Known issue? Or am I doing something stupid? It happens. 🙂
Stack trace:
kotlin.native.concurrent.FreezingException: freezing of SomeClass@3541f1f8 has failed, first blocker is SomeClass@3541f1f8
at kfun:kotlin.Throwable#<init>(kotlin.String?){} + 93 (kotlin/kotlin/Throwable.kt:23:37)
at kfun:kotlin.Exception#<init>(kotlin.String?){} + 91 (kotlin/kotlin/Exceptions.kt:23:44)
at kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 91 (kotlin/kotlin/Exceptions.kt:34:44)
at kfun:kotlin.native.concurrent.FreezingException#<init>(kotlin.Any;kotlin.Any){} + 643 (kotlin/kotlin/native/concurrent/Freezing.kt:15:9)
at ThrowFreezingException + 231 (kotlin/kotlin/native/concurrent/Internal.kt:87:15)
at FreezeSubgraph + 2815
at Kotlin_Worker_freezeInternal + 27
at kfun:kotlin.native.concurrent#freeze@0:0(){0§<kotlin.Any?>}0:0 + 62 (kotlin/kotlin/native/concurrent/Freezing.kt:33:5)
at kfun:kotlinx.coroutines.JobSupport.tryFinalizeSimpleState#internal + 1380 (JobSupport.kt:298:37)
at kfun:kotlinx.coroutines.JobSupport.tryMakeCompleting#internal + 809 (JobSupport.kt:868:17)
at kfun:kotlinx.coroutines.JobSupport#makeCompletingOnce(kotlin.Any?){}kotlin.Any? + 642 (JobSupport.kt:840:30)
at kfun:kotlinx.coroutines.intrinsics#startUndispatchedOrReturn@kotlinx.coroutines.internal.ScopeCoroutine<0:0>(0:1;kotlin.coroutines.SuspendFunction1<0:1,0:0>){0§<kotlin.Any?>;1§<kotlin.Any?>}kotlin.Any? + 1132 (intrinsics/Undispatched.kt:90:12)
at kfun:kotlinx.coroutines#withContext(kotlin.coroutines.CoroutineContext;kotlin.coroutines.SuspendFunction1<kotlinx.coroutines.CoroutineScope,0:0>){0§<kotlin.Any?>}0:0 + 1801 (Builders.common.kt:154:33)
at kfun:UnexpectedFreezing.$doTest$lambda-0COROUTINE$1.invokeSuspend#internal + 1045 (UnexpectedFreezing.kt:16:25)
at kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 758 (kotlin/kotlin/coroutines/ContinuationImpl.kt:30:39)
at kfun:kotlinx.coroutines.DispatchedTask#run(){} + 2802 (internal/DispatchedTask.kt:39:50)
at kfun:kotlinx.coroutines.EventLoopImplBase#processNextEvent(){}kotlin.Long + 838 (EventLoop.common.kt:274:18)
at kfun:kotlinx.coroutines#runEventLoop(kotlinx.coroutines.EventLoop?;kotlin.Function0<kotlin.Boolean>){} + 911 (Builders.kt:80:40)
at kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.start$lambda-0#internal + 407 (Workers.kt:49:17)
at kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.$start$lambda-0$FUNCTION_REFERENCE$35.invoke#internal + 62 (Workers.kt:47:24)
at kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.$start$lambda-0$FUNCTION_REFERENCE$35.$<bridge-UNN>invoke(){}#internal + 62 (Workers.kt:47:24)
at WorkerLaunchpad + 183 (kotlin/kotlin/native/concurrent/Internal.kt:69:54)
at _ZN6Worker19processQueueElementEb + 3135
at _ZN12_GLOBAL__N_113workerRoutineEPv + 54
at _pthread_start + 148
at thread_start + 15