-
Notifications
You must be signed in to change notification settings - Fork 182
Open
Description
When a service provides a suspend method, it still needs to be called on the right quickJs thread. This is quite unexpected for a suspend function.
It would be great if the library could do the thread jump to the dispatcher that was given during initialization, for suspend functions.
Currently, it seems to still work on JVM (probably by luck) but crashes on iOS with the following stacktrace (at the bottom). The iOS Zipline dispatcher in the sample is created the way as this one from redwood.
I can workaround the issue by creating a wrapper around the service that does:
class MyServiceWrapper(val dispatcher: CoroutineDispatcher, val delegate: MyZiplineService) : MyZiplineService {
override suspend fun echo(input: String): String = withContext(dispatcher) { // the dispatcher configured in the loader.
delegate.echo(input)
}
}
A possible quick fix is to change callSuspendingInternal to do a withContext(endpoint.scope.coroutineContext) but I'm not sure if that would have any side effects.
Uncaught Kotlin exception: app.cash.zipline.QuickJsException: stack overflow
Thread 4 Queue : com.apple.root.user-initiated-qos.cooperative (concurrent)
#0 0x0000000102e40874 in __pthread_kill ()
#1 0x0000000102a7a2ec in pthread_kill ()
#2 0x0000000180171ea8 in abort ()
#3 0x00000001043c755c in (anonymous namespace)::terminateWithUnhandledException(ObjHeader*)::$_1::operator()() const ()
#4 0x00000001043c7414 in (anonymous namespace)::$_0::operator()<(anonymous namespace)::terminateWithUnhandledException(ObjHeader*)::$_1> ()
#5 0x00000001043c7158 in (anonymous namespace)::terminateWithUnhandledException ()
#6 0x00000001043c712c in (anonymous namespace)::processUnhandledException ()
#7 0x0000000104508a2c in kfun:kotlinx.coroutines.internal#propagateExceptionFinalResort(kotlin.Throwable){} at /opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/internal/CoroutineExceptionHandlerImpl.kt:23
#8 0x00000001044dc4b8 in kfun:kotlinx.coroutines.internal#handleUncaughtCoroutineException(kotlin.coroutines.CoroutineContext;kotlin.Throwable){} at /opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/internal/CoroutineExceptionHandlerImpl.common.kt:48
#9 0x000000010448de4c in kfun:kotlinx.coroutines#handleCoroutineException(kotlin.coroutines.CoroutineContext;kotlin.Throwable){} at /opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/CoroutineExceptionHandler.kt:31
#10 0x0000000104482018 in kfun:kotlinx.coroutines.StandaloneCoroutine.handleJobException#internal at /opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/Builders.common.kt:194
#11 0x000000010450f5b8 in kfun:kotlinx.coroutines.JobSupport#handleJobException(kotlin.Throwable){}kotlin.Boolean-trampoline at /opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:1139
#12 0x00000001044975d8 in kfun:kotlinx.coroutines.JobSupport.finalizeFinishingState#internal at /opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:222
#13 0x000000010449ffd0 in kfun:kotlinx.coroutines.JobSupport.tryMakeCompletingSlowPath#internal at /opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:946
#14 0x000000010449f608 in kfun:kotlinx.coroutines.JobSupport.tryMakeCompleting#internal at /opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:894
#15 0x000000010449f110 in kfun:kotlinx.coroutines.JobSupport#makeCompletingOnce(kotlin.Any?){}kotlin.Any? [inlined] <inlined-lambda> [inlined] at /opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:859
#16 0x000000010449f100 in kfun:kotlinx.coroutines.JobSupport#makeCompletingOnce(kotlin.Any?){}kotlin.Any? [inlined] kfun:kotlinx.coroutines.JobSupport.loopOnState#internal [inlined] at /opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:170
#17 0x000000010449f0b4 in kfun:kotlinx.coroutines.JobSupport#makeCompletingOnce(kotlin.Any?){}kotlin.Any? at /opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:858
#18 0x000000010447fe84 in kfun:kotlinx.coroutines.AbstractCoroutine#resumeWith(kotlin.Result<1:0>){} at /opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/AbstractCoroutine.kt:99
#19 0x000000010437b200 in kfun:kotlin.coroutines.Continuation#resumeWith(kotlin.Result<1:0>){}-trampoline at /opt/buildAgent/work/7377bd4dc65e1c03/kotlin/libraries/stdlib/src/kotlin/coroutines/Continuation.kt:26
#20 0x0000000104275ddc in kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} [inlined] <inlined-lambda> [inlined] at /opt/buildAgent/work/7377bd4dc65e1c03/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/coroutines/ContinuationImpl.kt:43
#21 0x0000000104275b08 in kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} [inlined] kfun:kotlin#with(0:0;kotlin.Function1<0:0,0:1>){0§<kotlin.Any?>;1§<kotlin.Any?>}0:1 [inlined] at /opt/buildAgent/work/7377bd4dc65e1c03/kotlin/libraries/stdlib/src/kotlin/util/Standard.kt:70
#22 0x0000000104275ae8 in kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} at /opt/buildAgent/work/7377bd4dc65e1c03/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/coroutines/ContinuationImpl.kt:26
#23 0x000000010437b200 in kfun:kotlin.coroutines.Continuation#resumeWith(kotlin.Result<1:0>){}-trampoline at /opt/buildAgent/work/7377bd4dc65e1c03/kotlin/libraries/stdlib/src/kotlin/coroutines/Continuation.kt:26
#24 0x00000001044e025c in kfun:kotlinx.coroutines.DispatchedTask#run(){} [inlined] kfun:kotlin.coroutines#resume__at__kotlin.coroutines.Continuation<0:0>(0:0){0§<kotlin.Any?>} [inlined] at /opt/buildAgent/work/7377bd4dc65e1c03/kotlin/libraries/stdlib/src/kotlin/coroutines/Continuation.kt:45
#25 0x00000001044e01d0 in kfun:kotlinx.coroutines.DispatchedTask#run(){} [inlined] <inlined-lambda> [inlined] at /opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/internal/DispatchedTask.kt:100
#26 0x00000001044dfdac in kfun:kotlinx.coroutines.DispatchedTask#run(){} [inlined] kfun:kotlinx.coroutines#withContinuationContext(kotlin.coroutines.Continuation<*>;kotlin.Any?;kotlin.Function0<0:0>){0§<kotlin.Any?>}0:0 [inlined] at /opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/CoroutineContext.kt:44
#27 0x00000001044dfdac in kfun:kotlinx.coroutines.DispatchedTask#run(){} at /opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/internal/DispatchedTask.kt:82
#28 0x000000010450ea88 in kfun:kotlinx.coroutines.Runnable#run(){}-trampoline at /opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Runnable.kt:12
#29 0x00000001041cf3c0 in objc2kotlin_virtual_kfun:kotlinx.coroutines.Runnable#run(){} at /<compiler-generated>:1
#30 0x00000001042190ac in closure #1 in static SwiftCoroutineDispatcher.executeWithoutCancellation(dispatcher:) at /Users/yigit/src/ZiplinePlayground/shared/build/skie/binaries/debugFramework/DEBUG/iosSimulatorArm64/swift/generated/Skie/Skie.SwiftCoroutineDispatcher.swift:79
Metadata
Metadata
Assignees
Labels
No labels