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

FakeFileSystem throws InvalidMutabilityException on Kotlin/Native #950

Closed
kubode opened this issue Jun 2, 2021 · 3 comments
Closed

FakeFileSystem throws InvalidMutabilityException on Kotlin/Native #950

kubode opened this issue Jun 2, 2021 · 3 comments
Milestone

Comments

@kubode
Copy link

kubode commented Jun 2, 2021

Hi, thanks for working on making Okio to Kotlin Multiplatform.

I have encountered InvalidMutabilityException when testing with FakeFileSystem on Kotlin/Native.
However, it’s working with FileSystem.SYSTEM as intended.

Environment

  • Kotlin 1.4.32
  • Kotlin Coroutines 1.4.3-native-mt
  • com.squareup.okio:okio-multiplatform:3.0.0-alpha.6

Test code

    val path = "/path/to/file".toPath()

    @Test
    fun success() = runTest { // runTest: the same as runBlocking with Dispatchers.Main
        val fileSystem: FileSystem = FileSystem.SYSTEM
        val string = withContext(Dispatchers.Default) { fileSystem.read(path) { readUtf8() } }
        println(string)
    }

    @Test
    fun fail() = runTest {
        val fileSystem: FileSystem = FakeFileSystem()
        val string = withContext(Dispatchers.Default) { fileSystem.read(path) { readUtf8() } }
        println(string)
    }

Stack trace

kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen okio.fakefilesystem.FakeFileSystem.Element.File@d5c2b1e8
	at kotlin.Throwable#<init>(/Users/teamcity2/buildAgent/work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/Throwable.kt:23)
	at kotlin.Exception#<init>(/Users/teamcity2/buildAgent/work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/Exceptions.kt:23)
	at kotlin.RuntimeException#<init>(/Users/teamcity2/buildAgent/work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/Exceptions.kt:34)
	at kotlin.native.concurrent.InvalidMutabilityException#<init>(/Users/teamcity2/buildAgent/work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/native/concurrent/Freezing.kt:22)
	at <global>.ThrowInvalidMutabilityException(/Users/teamcity2/buildAgent/work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:93)
	at <global>.MutationCheck(Unknown Source)
	at okio.fakefilesystem.FakeFileSystem.Element.<set-lastAccessedAt>#internal(/Users/jwilson/Projects/okio/okio-fakefilesystem/src/commonMain/kotlin/okio/fakefilesystem/FakeFileSystem.kt:416)
	at okio.fakefilesystem.FakeFileSystem.Element.access#internal(/Users/jwilson/Projects/okio/okio-fakefilesystem/src/commonMain/kotlin/okio/fakefilesystem/FakeFileSystem.kt:442)
	at okio.fakefilesystem.FakeFileSystem.open#internal(/Users/jwilson/Projects/okio/okio-fakefilesystem/src/commonMain/kotlin/okio/fakefilesystem/FakeFileSystem.kt:315)
	at okio.fakefilesystem.FakeFileSystem#openReadOnly(/Users/jwilson/Projects/okio/okio-fakefilesystem/src/commonMain/kotlin/okio/fakefilesystem/FakeFileSystem.kt:260)
	at okio.fakefilesystem.FakeFileSystem#source(/Users/jwilson/Projects/okio/okio-fakefilesystem/src/commonMain/kotlin/okio/fakefilesystem/FakeFileSystem.kt:241)
	********
	at kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(/Users/teamcity2/buildAgent/work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/coroutines/ContinuationImpl.kt:30)
	at kotlinx.coroutines.DispatchedTask#run(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/internal/DispatchedTask.kt:106)
	at kotlinx.coroutines.EventLoopImplBase#processNextEvent(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/EventLoop.common.kt:277)
	at kotlinx.coroutines#runEventLoop(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Builders.kt:80)
	at kotlinx.coroutines.WorkerCoroutineDispatcherImpl.start$lambda-0#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Workers.kt:49)
	at kotlinx.coroutines.WorkerCoroutineDispatcherImpl.$start$lambda-0$FUNCTION_REFERENCE$35.invoke#internal(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Workers.kt:47)
	at kotlinx.coroutines.WorkerCoroutineDispatcherImpl.$start$lambda-0$FUNCTION_REFERENCE$35.$<bridge-UNN>invoke(/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Workers.kt:47)
	at <global>.WorkerLaunchpad(/Users/teamcity2/buildAgent/work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:70)
	at <global>._ZN6Worker19processQueueElementEb(Unknown Source)
	at <global>._ZN12_GLOBAL__N_113workerRoutineEPv(Unknown Source)
	at <global>._pthread_start(Unknown Source)
	at <global>.thread_start(Unknown Source)
@swankjesse
Copy link
Member

We might get this fixed for us for free with the new Kotlin/Native memory model. We need to adopt some locking in our FakeFileSystem for safe concurrent use.

@swankjesse swankjesse added this to the 3.0 milestone Sep 29, 2021
@swankjesse swankjesse mentioned this issue Sep 29, 2021
47 tasks
@swankjesse swankjesse modified the milestones: 3.0, Backlog Oct 26, 2021
@whataa
Copy link

whataa commented May 26, 2023

The new Kotlin/Native memory model has been released in kotlin 1.7.20, so is there any progress here

@kubode
Copy link
Author

kubode commented May 29, 2023

True. I close this issue.

@kubode kubode closed this as completed May 29, 2023
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