Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlinx.coroutines.flow.StateFlowImpl #2584

Closed
matt400m opened this issue Mar 15, 2021 · 1 comment

Comments

@matt400m
Copy link

Kotlin: 1.4.31
Version: 1.4.3-mt

After Kotlin update from 1.4.21 -> 1.4.31 I have a strange behaviour
in src/iosTest I have:

@Test
    fun testSingleThreadWithFreeze() {
        val f = MutableStateFlow(1)
        f.value = 2
        f.freeze()
        f.value = 3
        runBlocking {
            f.take(1).collect {
                println("got $it")
            }

            println("got ${f.value}")
        }
    }

and it's failed.

stacktrace:

kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlinx.coroutines.flow.StateFlowImpl@6e659b8
	at kotlin.Throwable#<init>(/Users/teamcity1/teamcity_work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/Throwable.kt:23)
	at kotlin.Exception#<init>(/Users/teamcity1/teamcity_work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/Exceptions.kt:23)
	at kotlin.RuntimeException#<init>(/Users/teamcity1/teamcity_work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/Exceptions.kt:34)
	at kotlin.native.concurrent.InvalidMutabilityException#<init>(/Users/teamcity1/teamcity_work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/native/concurrent/Freezing.kt:22)
	at <global>.ThrowInvalidMutabilityException(/Users/teamcity1/teamcity_work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:93)
	at <global>.MutationCheck(Unknown Source)
	at kotlinx.coroutines.flow.StateFlowImpl.<set-sequence>#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/flow/StateFlow.kt:263)
	at kotlinx.coroutines.flow.StateFlowImpl.updateState#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/flow/StateFlow.kt:284)
	at kotlinx.coroutines.flow.StateFlowImpl.<set-value>#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/flow/StateFlow.kt:268)
	at <global>.MutableFlowStateTest#testSingleThreadWithFreeze(/Users//projekty/-common-shared/Sources/shared/src/iosTest/kotlin/MutableFlowStateTest.kt:34)
	at $MutableFlowStateTest$test$0.$testSingleThreadWithFreeze$FUNCTION_REFERENCE$182.invoke#internal(/Users//projekty/-common-shared/Sources/shared/src/iosTest/kotlin/MutableFlowStateTest.kt:30)
	at $MutableFlowStateTest$test$0.$testSingleThreadWithFreeze$FUNCTION_REFERENCE$182.$<bridge-UNNN>invoke(/Users///-common-shared/Sources/shared/src/iosTest/kotlin/MutableFlowStateTest.kt:30)
	at kotlin.native.internal.test.BaseClassSuite.TestCase#run(/Users/teamcity1/teamcity_work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/native/internal/test/TestSuite.kt:85)
	at kotlin.native.internal.test.TestRunner.run#internal(/Users/teamcity1/teamcity_work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/native/internal/test/TestRunner.kt:241)
	at kotlin.native.internal.test.TestRunner.runIteration#internal(/Users/teamcity1/teamcity_work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/native/internal/test/TestRunner.kt:265)
	at kotlin.native.internal.test.TestRunner#run(/Users/teamcity1/teamcity_work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/native/internal/test/TestRunner.kt:280)
	at kotlin.native.internal.test#testLauncherEntryPoint(/Users/teamcity1/teamcity_work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/native/internal/test/Launcher.kt:22)
	at kotlin.native.internal.test#main(/Users/teamcity1/teamcity_work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/native/internal/test/Launcher.kt:26)
	at <global>.Konan_start(/Users/teamcity1/teamcity_work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/native/internal/test/Launcher.kt:25)
	at <global>.Init_and_run_start(Unknown Source)
	at <global>.start(Unknown Source)
	at <global>.0x0(Unknown Source)

But when I write f.value.freeze() I don't have an exception kotlin.native.concurrent.InvalidMutabilityException:

working:

 @Test
    fun testSingleThreadWithFreeze() {
        val f = MutableStateFlow(1)
        f.value = 2
        f.value.freeze()
        f.value = 3
        runBlocking {
            f.take(1).collect {
                println("got $it")
            }

            println("got ${f.value}")
        }
    }
@qwwdfsad
Copy link
Collaborator

It seems like it was some kind of a stuck update, in that scenario, it's typically worth to make full clean build and reset IDEA caches.

This very problem was fixed in 1.4.3-native-mt and non-reproducible with Kotlin 1.5.0 and coroutines 1.5.0-native-mt as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants