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 io.ktor.client.request.HttpRequestPipeline@545e18f8 #887

Closed
wuseal opened this issue Jan 19, 2019 · 8 comments

Comments

@wuseal
Copy link

commented Jan 19, 2019

Ktor Version

implementation("io.ktor:ktor-client-ios:1.1.1")

Ktor Engine Used(client or server and name)

Client

JVM Version, Operating System and Relevant Context

MBP 2017 JVM 1.8

Feedback

This exception was printed out,and the test can't print out the expected result

    suspend fun getDemoJSONDataFromNet(): String {


        val result = client.get<String>("https://en.wikipedia.org/wiki/Main_Page")

        Logger.d(tag, "the return data is $result")

        return result
    }
fun getDataIos(callBack: (result: String) -> Unit) {
    runBlocking {
       val job = async {
            val result = HttpUtil.getDemoJSONDataFromNet()
            Logger.d("SimpleIos","result value is $result")
            callBack(result)
        }
        job.await()
    }
}
    @Test
    fun testGetData() {
        getDataIos {
            println(it)
        }
    }

Exception Log:

Instances of kotlin.Error, kotlin.RuntimeException and subclasses aren't propagated from Kotlin to Objective-C/Swift.
Other exceptions can be propagated as NSError if method has or inherits @Throws annotation.
Uncaught Kotlin exception: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen io.ktor.client.request.HttpRequestPipeline@2ef2a08
        at 0   app                                 0x000000010dba2896 kfun:kotlin.Exception.<init>(kotlin.String?)kotlin.Exception + 70
        at 1   app                                 0x000000010dba27b6 kfun:kotlin.RuntimeException.<init>(kotlin.String?)kotlin.RuntimeException + 70
        at 2   app                                 0x000000010dba40e6 kfun:kotlin.native.concurrent.InvalidMutabilityException.<init>(kotlin.String)kotlin.native.concurrent.InvalidMutabilityException + 70
        at 3   app                                 0x000000010dc3c6b8 ThrowInvalidMutabilityException + 280
        at 4   app                                 0x000000010dc5ee48 MutationCheck + 24
        at 5   app                                 0x000000010dce8a83 kfun:io.ktor.util.pipeline.Pipeline.<set-interceptors>#internal + 67
        at 6   app                                 0x000000010dce86a6 kfun:io.ktor.util.pipeline.Pipeline.notSharedInterceptorsList#internal + 70
        at 7   app                                 0x000000010dce84d6 kfun:io.ktor.util.pipeline.Pipeline.cacheInterceptors#internal + 710
        at 8   app                                 0x000000010dce6292 kfun:io.ktor.util.pipeline.Pipeline.sharedInterceptorsList#internal + 98
        at 9   app                                 0x000000010dce61ca kfun:io.ktor.util.pipeline.Pipeline.createContext$ktor-utils(#GENERIC_kotlin.Any;#GENERIC_kotlin.Any)io.ktor.util.pipeline.PipelineExecutor<#GENERIC_kotlin.Any> + 90
        at 10  app                                 0x000000010dce60f0 kfun:io.ktor.util.pipeline.Pipeline.execute(#GENERIC_kotlin.Any;#GENERIC_kotlin.Any)#GENERIC_kotlin.Any + 96
        at 11  app                                 0x000000010dd313a8 kfun:io.ktor.client.HttpClient.$execute$COROUTINE$1.invokeSuspend(kotlin.Result<kotlin.Any?>)kotlin.Any? + 296
        at 12  app                                 0x000000010dd31522 kfun:io.ktor.client.HttpClient.execute(io.ktor.client.request.HttpRequestBuilder)io.ktor.client.call.HttpClientCall + 130
        at 13  app                                 0x000000010dd32696 kfun:io.ktor.client.call.$call$COROUTINE$3.invokeSuspend(kotlin.Result<kotlin.Any?>)kotlin.Any? + 758
        at 14  app                                 0x000000010dd32852 kfun:io.ktor.client.call.call@io.ktor.client.HttpClient.(kotlin.coroutines.SuspendFunction1<io.ktor.client.request.HttpRequestBuilder,kotlin.Unit>)io.ktor.client.call.HttpClientCall + 130
        at 15  app                                 0x000000010dd330eb kfun:io.ktor.client.call.call@io.ktor.client.HttpClient.(io.ktor.client.request.HttpRequestBuilder)io.ktor.client.call.HttpClientCall + 123
        at 16  app                                 0x000000010db97f3f kfun:sample.HttpUtil.$getDemoJSONDataFromNet$COROUTINE$0.invokeSuspend(kotlin.Result<kotlin.Any?>)kotlin.Any? + 1551
        at 17  app                                 0x000000010db97821 kfun:sample.HttpUtil.getDemoJSONDataFromNet()kotlin.String + 113
        at 18  app                                 0x000000010dba0de9 kfun:sample.$getDataIos$lambda-1$lambda-0$COROUTINE$3.invokeSuspend(kotlin.Result<kotlin.Any?>)kotlin.Any? + 313
        at 19  app                                 0x000000010dbd4801 kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) + 385
        at 20  app                                 0x000000010dca7b89 kfun:kotlinx.coroutines.DispatchedTask.run() + 1129
        at 21  app                                 0x000000010dca92d6 kfun:kotlinx.coroutines.EventLoopImpl.processNextEvent()ValueType + 422
        at 22  app                                 0x000000010dccf7f7 kfun:kotlinx.coroutines.BlockingCoroutine.joinBlocking#internal + 263
        at 23  app                                 0x000000010dccf5d7 kfun:kotlinx.coroutines.runBlocking(kotlin.coroutines.CoroutineContext;kotlin.coroutines.SuspendFunction1<kotlinx.coroutines.CoroutineScope,#GENERIC>)Generic + 983
        at 24  app                                 0x000000010dccfb4c kfun:kotlinx.coroutines.runBlocking$default(kotlin.coroutines.CoroutineContext;kotlin.coroutines.SuspendFunction1<kotlinx.coroutines.CoroutineScope,#GENERIC>;kotlin.Int)Generic + 204
        at 25  app                                 0x000000010dba06e4 kfun:sample.getDataIos(kotlin.Function1<kotlin.String,kotlin.Unit>) + 100
        at 26  app                                 0x000000010dba0618 kfun:sample.main(kotlin.Array<kotlin.String>) + 216
        at 27  iosApp                              0x000000010d897774 $S6iosApp14ViewControllerC11viewDidLoadyyFTo + 36
        at 28  UIKitCore                           0x0000000112ea84e1 -[UIViewController loadViewIfRequired] + 1186

@cy6erGn0m cy6erGn0m added the bug label Jan 19, 2019

@e5l e5l added this to the 1.2.0 milestone Jan 25, 2019

@e5l

This comment has been minimized.

Copy link
Contributor

commented Jan 25, 2019

Hi @wuseal, thanks for the report.
Could you change runBlocking to launch(Dispatchers.Unconfined)?

@rdbatch02

This comment has been minimized.

Copy link

commented May 4, 2019

I'm seeing this same issue on 1.2.0-rc using the Native client on Linux. I've tried using launch(Dispatches.Unconfined) as suggested by @e5l and the exception appears to be the same:

Versions:
Multiplatform Plugin 1.3.31
io.ktor:ktor-client-core-native:1.2.0-rc
io.ktor:ktor-client-curl:1.2.0-rc
org.jetbrains.kotlinx:kotlinx-coroutines-core-native:1.2.1

kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen io.ktor.client.request.HttpRequestPipeline@18834a8
        at  (0x398d9a)
        at kfun:io.ktor.util.pipeline.Pipeline.execute(#GENERIC_kotlin.Any;#GENERIC_kotlin.Any)#GENERIC_kotlin.Any (0x363e9d)
        at kfun:io.ktor.client.HttpClient.$execute$COROUTINE$11.invokeSuspend#internal (0x374d60)
        at kfun:io.ktor.client.call.$call$COROUTINE$15.invokeSuspend#internal (0x374a5e)
        at kfun:io.ktor.client.call.call@io.ktor.client.HttpClient.(io.ktor.client.request.HttpRequestBuilder)io.ktor.client.call.HttpClientCall (0x370c3e)
        at kfun:com.batchofcode.lambdaruntime.client.CommonAwsRuntimeClient.$processRequests$COROUTINE$1.invokeSuspend#internal (0x36c0b8)
        at kfun:com.batchofcode.lambdaruntime.client.CommonAwsRuntimeClient.$run$COROUTINE$0.invokeSuspend#internal (0x36b82c)
        at kfun:com.batchofcode.lambdaruntime.client.LambdaRuntimeClient.$run$lambda-0$COROUTINE$3.invokeSuspend#internal (0x28e65d)
        at kfun:kotlin.coroutines.native.internal.BaseContinuationImpl.resumeWith(kotlin.Result<kotlin.Any?>) (0x27aa64)
        at kfun:kotlinx.coroutines.resumeCancellable$kotlinx-coroutines-core@kotlin.coroutines.Continuation<#GENERIC>.(#GENERIC)Generic (0x27d90d)
        at kfun:kotlinx.coroutines.intrinsics.startCoroutineCancellable$kotlinx-coroutines-core@kotlin.coroutines.SuspendFunction1<#GENERIC,#GENERIC>.(#GENERIC;kotlin.coroutines.Continuation<#GENERIC>)Generic (0x28da9c)
        at kfun:kotlinx.coroutines.launch$default@kotlinx.coroutines.CoroutineScope.(kotlin.coroutines.CoroutineContext;kotlinx.coroutines.CoroutineStart;kotlin.coroutines.SuspendFunction1<kotlinx.coroutines.CoroutineScope,kotlin.Unit>;kotlin.Int)kotlinx.coroutines.Job (0x28c4cf)
        at Konan_start (0x28bd0d)
        at Konan_run_start (0x28ba73)
        at Konan_main (0x28b9c7)
        at __libc_start_main (0x7f9ff76d7445)
        at  (0x260029)
        at  ((nil))
kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for DispatchedContinuation[Unconfined, Continuation @ $<init>$lambda-2$COROUTINE$6]. Please read KDoc to 'handleFatalException' method and report this incident to maintainers; caused by kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlinx.atomicfu.AtomicRef@18393a8
        at kfun:kotlinx.coroutines.DispatchedTask.run() (0x27f54a)
        at kfun:kotlinx.coroutines.EventLoop.processUnconfinedEvent()ValueType (0x27e636)
        at kfun:kotlinx.coroutines.resumeCancellable$kotlinx-coroutines-core@kotlin.coroutines.Continuation<#GENERIC>.(#GENERIC)Generic (0x27d9b8)
        at kfun:kotlinx.coroutines.intrinsics.startCoroutineCancellable$kotlinx-coroutines-core@kotlin.coroutines.SuspendFunction1<#GENERIC,#GENERIC>.(#GENERIC;kotlin.coroutines.Continuation<#GENERIC>)Generic (0x28da9c)
        at kfun:kotlinx.coroutines.launch$default@kotlinx.coroutines.CoroutineScope.(kotlin.coroutines.CoroutineContext;kotlinx.coroutines.CoroutineStart;kotlin.coroutines.SuspendFunction1<kotlinx.coroutines.CoroutineScope,kotlin.Unit>;kotlin.Int)kotlinx.coroutines.Job (0x28c4cf)
        at Konan_start (0x28bd0d)
        at Konan_run_start (0x28ba73)
        at Konan_main (0x28b9c7)
        at __libc_start_main (0x7f9ff76d7445)
        at  (0x260029)
        at  ((nil))
@Syex

This comment has been minimized.

Copy link

commented May 7, 2019

Having the same issue right now, with ktor 1.1.4 and 1.2.0-rc

@Ribesg

This comment has been minimized.

Copy link

commented May 14, 2019

Don't freeze your HttpClient, it doesn't work.

That means don't put it inside an object for example, or inside an instance of a class stored inside an object, etc

@Syex

This comment has been minimized.

Copy link

commented May 14, 2019

Thanks @Ribesg that totally was my problem.

@rdbatch02

This comment has been minimized.

Copy link

commented May 15, 2019

Same here, thanks @Ribesg!

@tonilopezmr

This comment has been minimized.

Copy link

commented Jul 21, 2019

Having the same issue in version 1.2.2 only on IOS even if using ThreadLocal

@e5l

This comment has been minimized.

Copy link
Contributor

commented Sep 12, 2019

Fixed in 1.2.4

@e5l e5l closed this Sep 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.