cashapp / zipline

Run Kotlin/JS libraries in Kotlin/JVM and Kotlin/Native programs
Apache License 2.0
2.03k stars 153 forks source link

Stack Overflow after 1.2.0, because of shared commit. #1163

Open Shabinder opened 10 months ago

Shabinder commented 10 months ago

Some Traces thrown from plugins are very opaque on the cause of the crash, or am I missing something here ?

app.cash.zipline.ZiplineException: CompletionHandlerException: Exception in completion handler InvokeOnCompletion@4[job@5] for DeferredCoroutine{Completed}@5
                                                                                                        at captureStack (runtime/coreRuntime.kt:12)
                                                                                                        at CompletionHandlerException (mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/Exceptions.common.kt:1813)
                                                                                                        at notifyCompletion (mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:158)
                                                                                                        at completeStateFinalization (mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:325)
                                                                                                        at finalizeFinishingState (mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:236)
                                                                                                        at tryMakeCompletingSlowPath (mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:910)
                                                                                                        at tryMakeCompleting (mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:867)
                                                                                                        at <anonymous> (mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:832)
                                                                                                        at <anonymous> (mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/AbstractCoroutine.kt:99)
                                                                                                        at <anonymous> (src/kotlin/coroutines_13/CoroutineImpl.kt:45)
                                                                                                        at <anonymous> (kotlin-kotlin-stdlib-js-ir.js)
                                                                                                        at <anonymous> (mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/internal/DispatchedTask.kt:112)
                                                                                                        at <anonymous> (mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/js/src/JSDispatcher.kt:155)
                                                                                                        at <anonymous> (mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/js/src/JSDispatcher.kt)
                                                                                                        at apply (native)
                                                                                                        at <anonymous> (runner/work/zipline/zipline/zipline/src/jsMain/kotlin/app/cash/zipline/GlobalBridge.kt:72)
                                                                                                        at <anonymous> (runner/work/zipline/zipline/zipline/src/commonMain/kotlin/app/cash/zipline/internal/GuestService.kt)
                                                                                                        at <anonymous> (zipline-root-zipline.js)
                                                                                                        at <anonymous> (runner/work/zipline/zipline/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/InboundService.kt:53)
                                                                                                        at <anonymous> (runner/work/zipline/zipline/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/Endpoint.kt:99)
                                                                                                        at <anonymous> (zipline-root-zipline.js)
                                                                                                        at <anonymous> (runner/work/zipline/zipline/zipline/src/jsMain/kotlin/app/cash/zipline/GlobalBridge.kt)
                                                                                                        at <anonymous> (zipline-root-zipline.js)
                                                                                                        Suppressed: DiagnosticCoroutineContextException: [DeferredCoroutine{Completed}@5, SetTimeoutDispatcher@3]
                                                                                                        at captureStack (runtime/coreRuntime.kt:12)
                                                                                                        at DiagnosticCoroutineContextException (mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/js/src/internal/CoroutineExceptionHandlerImpl.kt:8709)
                                                                                                        at handleUncaughtCoroutineException (mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/internal/CoroutineExceptionHandlerImpl.common.kt:46)
                                                                                                        at handleCoroutineException (mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/CoroutineExceptionHandler.kt:32)
                                                                                                        at <anonymous> (mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/AbstractCoroutine.kt:107)
                                                                                                        at notifyCompletion (mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:158)
                                                                                                            ... and 21 more common stack frames skipped
                                                                                                    Caused by:     at captureStack (runtime/coreRuntime.kt:12)
                                                                                                        at ClassCastException_init_$Create$ (kotlin-kotlin-stdlib-js-ir.js)
                                                                                                        at THROW_CCE (runtime/hacks.kt)
                                                                                                        at <anonymous> (soundbound-extensions-lib.js)
                                                                                                        at <anonymous> (opt/buildAgent/work/b2fef8360e1bcf3d/formats/json/commonMain/src/kotlinx/serialization/json/internal/Polymorphic.kt:20)
                                                                                                        at <anonymous> (opt/buildAgent/work/b2fef8360e1bcf3d/core/commonMain/src/kotlinx/serialization/encoding/AbstractEncoder.kt:80)
                                                                                                        at <anonymous> (opt/buildAgent/work/b2fef8360e1bcf3d/core/commonMain/src/kotlinx/serialization/internal/CollectionSerializers.kt:68)
                                                                                                        at <anonymous> (kotlinx-serialization-kotlinx-serialization-core.js)
                                                                                                        at <anonymous> (opt/buildAgent/work/b2fef8360e1bcf3d/formats/json/commonMain/src/kotlinx/serialization/json/internal/Polymorphic.kt:20)
2023-11-07 23:30:07.725   813-891   Zipline                 in.shabinder.soundbound.preview      E      at <anonymous> (opt/buildAgent/work/b2fef8360e1bcf3d/core/commonMain/src/kotlinx/serialization/encoding/AbstractEncoder.kt:80)
                                                                                                        at <anonymous> (commonMainSources/libraries/stdlib/src/kotlin/util/Preconditions.kt:1876)
                                                                                                        at <anonymous> (zipline-root-zipline.js)
                                                                                                        at <anonymous> (opt/buildAgent/work/b2fef8360e1bcf3d/formats/json/commonMain/src/kotlinx/serialization/json/internal/Polymorphic.kt:20)
                                                                                                        at <anonymous> (opt/buildAgent/work/b2fef8360e1bcf3d/core/commonMain/src/kotlinx/serialization/encoding/AbstractEncoder.kt:80)
                                                                                                        at <anonymous> (opt/buildAgent/work/b2fef8360e1bcf3d/core/commonMain/src/kotlinx/serialization/encoding/Encoding.kt:92)
                                                                                                        at <anonymous> (zipline-root-zipline.js)
                                                                                                        at <anonymous> (opt/buildAgent/work/b2fef8360e1bcf3d/formats/json/commonMain/src/kotlinx/serialization/json/internal/Polymorphic.kt:20)
                                                                                                        at encodeToDynamic_0 (opt/buildAgent/work/b2fef8360e1bcf3d/formats/json/jsMain/src/kotlinx/serialization/json/internal/DynamicEncoders.kt:42)
                                                                                                        at encodeToDynamic (opt/buildAgent/work/b2fef8360e1bcf3d/formats/json/jsMain/src/kotlinx/serialization/json/Dynamics.kt)
                                                                                                        at encodeToStringFast (runner/work/zipline/zipline/zipline/src/jsMain/kotlin/app/cash/zipline/internal/jsonJs.kt)
                                                                                                        at <anonymous> (runner/work/zipline/zipline/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/CallCodec.kt:56)
                                                                                                        at <anonymous> (runner/work/zipline/zipline/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/OutboundCallHandler.kt:99)
                                                                                                        at <anonymous> (runner/work/zipline/zipline/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/SuspendCallback.kt)
                                                                                                        at <anonymous> (zipline-root-zipline.js)
                                                                                                        at <anonymous> (runner/work/zipline/zipline/zipline/src/commonMain/kotlin/app/cash/zipline/internal/bridge/InboundService.kt:53)
                                                                                                        at <anonymous> (mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt)
                                                                                                        at <anonymous> (kotlinx.coroutines-kotlinx-coroutines-core-js-ir.js)
                                                                                                        at notifyCompletion (mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:369)
                                                                                                        at completeStateFinalization (mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:325)
                                                                                                        ... and 20 more common stack frames skipped
                                                                                                        at app.cash.zipline.internal.GuestService$Companion$Adapter$GeneratedOutboundService.runJob(GuestService.kt:23)
                                                                                                        at app.cash.zipline.internal.CoroutineEventLoop$DelayedJob$run$1.invokeSuspend(CoroutineEventLoop.kt:61)
                                                                                                        at app.cash.zipline.internal.CoroutineEventLoop$DelayedJob$run$1.invoke(Unknown Source:8)
                                                                                                        at app.cash.zipline.internal.CoroutineEventLoop$DelayedJob$run$1.invoke(Unknown Source:4)
                                                                                                        at kotlinx.coroutines.intrinsics.UndispatchedKt.startCoroutineUndispatched(Undispatched.kt:44)
                                                                                                        at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:112)
                                                                                                        at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126)
                                                                                                        at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56)
                                                                                                        at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
                                                                                                        at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
                                                                                                        at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
                                                                                                        at app.cash.zipline.internal.CoroutineEventLoop$DelayedJob.run(CoroutineEventLoop.kt:58)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
                                                                                                        at java.lang.Thread.run(Thread.java:1012)
Shabinder commented 10 months ago
image
Shabinder commented 9 months ago

Thread with all details. https://kotlinlang.slack.com/archives/C5HT9AL7Q/p1700181390990159?thread_ts=1691432897.694099&cid=C5HT9AL7Q

Shabinder commented 5 months ago

Any update ?

have been stuck on kotlin 1.9.10 and zipline 1.2.0, since above doesnt work. I am more than happy to provide info in any way possible or do a brief sync explaining the steps to repro same.

Case 1: ✅

Case 3: 🔴

image
Shabinder commented 4 months ago

After many iteration on finding out what works and what doesnt,

Below Commit is what makes the difference, with commit, plugins are loaded as expected, without, get stackOverflow error as shown.

https://github.com/Shabinder/zipline/commit/801b3d66cbe9ae2d51a44c7b272dff3c28409aa2

Shortlisted as much as I could, lmk if I can help or diagnose it more in any other way

JakeWharton commented 4 months ago

So it seems like a type with a recursive descriptor. We can change the calculation to put in a placeholder character for when it recurses by keeping a set of seen types. Will have to try and reproduce, but should be pretty easy give what you've found out so far.

minteemer commented 2 months ago

Got the same exception when using JsonElement as return type of a suspending ZiplineService method:

interface ExampleService : ZiplineService {

  suspend fun example(): JsonElement
}

JsonElement might be JsonArray or JsonObject, which in turn contains List<JsonElement> or Map<String, JsonElement>, thus recursion appears. A big problem for us, as we wanted to use JsonElement as a return type to get abstract tree of analytics params this way.

This exception does not seem to appear when using JsonElement in return type of non-suspending functions or when using it in function parameters.

Shabinder commented 4 weeks ago

@JakeWharton your hunch was r8, took time and dug in more today:

this is the class which ends in endless recursion

in.shabinder.soundbound.models.ThrowableWrapper(
message: kotlin.String, 
stackTrace: kotlin.String,
cause: in.shabinder.soundbound.models.ThrowableWrapper?
)?
image