iOS: com.dokar.quickjs.QuickJsException: InternalError: stack overflow
com.dokar.quickjs.QuickJsException: InternalError: stack overflow
at <anonymous> (main.js)
at <anonymous> (main.js)
at <anonymous> (main.js)
at <anonymous> (main.js)
at <anonymous> (main.js)
at Qu (main.js)
at <anonymous> (main.js)
at call (native)
at <anonymous> (main.js)
at Ut (main.js)
at ce (main.js)
at ve (main.js)
at <anonymous> (main.js)
at <anonymous> (main.js)
at xn (main.js)
at kn (main.js)
at <anonymous> (main.js)
at te (main.js)
at ne (main.js)
at <anonymous> (main.js)
at <anonymous> (main.js)
at <anonymous> (main.js)
at <anonymous> (main.js)
at <anonymous> (main.js)
at <anonymous> (main.js)
at <eval> (main.js:5)
Uncaught Kotlin exception: at 0 KKit 0x1032652c3 kfun:kotlin.Throwable#<init>(){} + 95
at 1 KKit 0x10325e4ef kfun:kotlin.Exception#<init>(){} + 87
at 2 KKit 0x1035e5ab3 kfun:com.dokar.quickjs.QuickJsException#<init>(kotlin.String?){} + 87
at 3 KKit 0x103604cd3 kfun:com.dokar.quickjs.bridge.newKtError#internal + 3611
at 4 KKit 0x103601fab kfun:com.dokar.quickjs.bridge#jsErrorToKtError(kotlinx.cinterop.CPointer<quickjs.JSContext>;kotlinx.cinterop.CValue<quickjs.JSValue>){}kotlin.Throwable + 5083
at 5 KKit 0x1035ff997 kfun:com.dokar.quickjs.bridge#toKtValue__at__kotlinx.cinterop.CValue<quickjs.JSValue>(kotlinx.cinterop.CPointer<quickjs.JSContext>){}kotlin.Any? + 5287
at 6 KKit 0x10361d673 kfun:com.dokar.quickjs.bridge.promiseRejectionHandler#internal + 491
at 7 KKit 0x10361d90f _717569636b6a732d6b743a717569636b6a732f55736572732f72756e6e65722f776f726b2f717569636b6a732d6b742f717569636b6a732d6b742f717569636b6a732f7372632f6e61746976654d61696e2f6b6f746c696e2f636f6d2f646f6b61722f717569636b6a732f6272696467652f70726f6d69736552656a656374696f6e48616e646c65722e6b74_knbridge0 + 307
at 8 KKit 0x103622273 _717569636b6a732d6b743a717569636b6a732f55736572732f72756e6e65722f776f726b2f717569636b6a732d6b742f717569636b6a732d6b742f717569636b6a732f7372632f6e61746976654d61696e2f6b6f746c696e2f636f6d2f646f6b61722f717569636b6a732f6272696467652f70726f6d69736552656a656374696f6e48616e646c65722e6b74_kncfun3 + 63
at 9 KKit 0x102ae122f fulfill_or_reject_promise + 347
at 10 KKit 0x102aa524f js_promise_resolve_function_call + 651
at 11 KKit 0x102a901fb JS_CallInternal + 599
at 12 KKit 0x102a8ff87 JS_Call + 107
at 13 KKit 0x102ae18db js_async_function_resume + 211
at 14 KKit 0x102aa5533 js_async_function_resolve_call + 299
at 15 KKit 0x102a901fb JS_CallInternal + 599
at 16 KKit 0x102a8ff87 JS_Call + 107
at 17 KKit 0x102ac91bb promise_reaction_job + 371
at 18 KKit 0x102a79b4b JS_ExecutePendingJob + 131
at 19 KKit 0x1035f5f4f kfun:com.dokar.quickjs.bridge#executePendingJob(kotlinx.cinterop.CPointer<quickjs.JSRuntime>){}com.dokar.quickjs.bridge.ExecuteJobResult + 847
at 20 KKit 0x1035f0503 kfun:com.dokar.quickjs.QuickJs.$invokeAsyncFunction$lambda$2COROUTINE$7.invokeSuspend#internal + 3755
at 21 KKit 0x1035f089b kfun:com.dokar.quickjs.QuickJs.invokeAsyncFunction$lambda$2#internal + 451
at 22 KKit 0x1035f0e63 kfun:com.dokar.quickjs.QuickJs.$invokeAsyncFunction$lambda$2$FUNCTION_REFERENCE$2.invoke#internal + 151
at 23 KKit 0x103390e3f kfun:kotlin.Function2#invoke(1:0;1:1){}1:2-trampoline + 115
at 24 KKit 0x10326deab kfun:kotlin.coroutines.intrinsics.object-4.invokeSuspend#internal + 731
at 25 KKit 0x10339075b kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#invokeSuspend(kotlin.Result<kotlin.Any?>){}kotlin.Any?-trampoline + 67
at 26 KKit 0x10326aaa3 kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 623
at 27 KKit 0x10339083b kfun:kotlin.coroutines.Continuation#resumeWith(kotlin.Result<1:0>){}-trampoline + 99
at 28 KKit 0x10347382b kfun:kotlinx.coroutines.DispatchedTask#run(){} + 1879
at 29 KKit 0x1034a1d77 kfun:kotlinx.coroutines.Runnable#run(){}-trampoline + 91
at 30 KKit 0x10349962f kfun:kotlinx.coroutines.MultiWorkerDispatcher.$workerRunLoop$lambda$2COROUTINE$0.invokeSuspend#internal + 1467
at 31 KKit 0x10339075b kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#invokeSuspend(kotlin.Result<kotlin.Any?>){}kotlin.Any?-trampoline + 67
at 32 KKit 0x10326aaa3 kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 623
at 33 KKit 0x10339083b kfun:kotlin.coroutines.Continuation#resumeWith(kotlin.Result<1:0>){}-trampoline + 99
at 34 KKit 0x10347382b kfun:kotlinx.coroutines.DispatchedTask#run(){} + 1879
at 35 KKit 0x1034a1d77 kfun:kotlinx.coroutines.Runnable#run(){}-trampoline + 91
at 36 KKit 0x10341c027 kfun:kotlinx.coroutines.EventLoopImplBase#processNextEvent(){}kotlin.Long + 287
at 37 KKit 0x1034a1ac3 kfun:kotlinx.coroutines.EventLoop#processNextEvent(){}kotlin.Long-trampoline + 51
at 38 KKit 0x103492bb3 kfun:kotlinx.coroutines.BlockingCoroutine.joinBlocking#internal + 435
at 39 KKit 0x103491a17 kfun:kotlinx.coroutines#runBlocking(kotlin.coroutines.CoroutineContext;kotlin.coroutines.SuspendFunction1<kotlinx.coroutines.CoroutineScope,0:0>){0§<kotlin.Any?>}0:0 + 1391
at 40 KKit 0x103491bf7 kfun:kotlinx.coroutines#runBlocking$default(kotlin.coroutines.CoroutineContext?;kotlin.coroutines.SuspendFunction1<kotlinx.coroutines.CoroutineScope,0:0>;kotlin.Int){0§<kotlin.Any?>}0:0 + 239
at 41 KKit 0x103497973 kfun:kotlinx.coroutines.MultiWorkerDispatcher.workerRunLoop#internal + 183
at 42 KKit 0x103498cef kfun:kotlinx.coroutines.MultiWorkerDispatcher.<init>$lambda$1$lambda$0#internal + 67
at 43 KKit 0x103499feb kfun:kotlinx.coroutines.MultiWorkerDispatcher.$<init>$lambda$1$lambda$0$FUNCTION_REFERENCE$5.invoke#internal + 71
at 44 KKit 0x10349a0bb kfun:kotlinx.coroutines.MultiWorkerDispatcher.$<init>$lambda$1$lambda$0$FUNCTION_REFERENCE$5.$<bridge-UNN>invoke(){}#internal + 71
at 45 KKit 0x10338d167 kfun:kotlin.Function0#invoke(){}1:0-trampoline + 99
at 46 KKit 0x103276b03 WorkerLaunchpad + 131
at 47 KKit 0x1033ed5f7 _ZN6Worker19processQueueElementEb + 2635
at 48 KKit 0x1033eca37 _ZN12_GLOBAL__N_113workerRoutineEPv + 219
at 49 libsystem_pthread.dylib 0x10591b413 _pthread_start + 103
at 50 libsystem_pthread.dylib 0x1059165df thread_start + 7
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [androidx.compose.runtime.BroadcastFrameClock@66c0528, StandaloneCoroutine{Cancelling}@d1d3290, FlushCoroutineDispatcher@6d74160]
at 0 KKit 0x10326512b kfun:kotlin.Throwable#<init>(kotlin.String?){} + 119
at 1 KKit 0x10325e577 kfun:kotlin.Exception#<init>(kotlin.String?){} + 115
at 2 KKit 0x10325e797 kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 115
at 3 KKit 0x10349b427 kfun:kotlinx.coroutines.internal.DiagnosticCoroutineContextException#<init>(kotlin.coroutines.CoroutineContext){} + 167
at 4 KKit 0x10346facb kfun:kotlinx.coroutines.internal#handleUncaughtCoroutineException(kotlin.coroutines.CoroutineContext;kotlin.Throwable){} + 647
at 5 KKit 0x103417b57 kfun:kotlinx.coroutines#handleCoroutineException(kotlin.coroutines.CoroutineContext;kotlin.Throwable){} + 515
at 6 KKit 0x10340b5a7 kfun:kotlinx.coroutines.StandaloneCoroutine.handleJobException#internal + 167
at 7 KKit 0x1034a353f kfun:kotlinx.coroutines.JobSupport#handleJobException(kotlin.Throwable){}kotlin.Boolean-trampoline + 59
at 8 KKit 0x103421d27 kfun:kotlinx.coroutines.JobSupport.finalizeFinishingState#internal + 1131
at 9 KKit 0x103429b43 kfun:kotlinx.coroutines.JobSupport.tryMakeCompletingSlowPath#internal + 2207
at 10 KKit 0x10342926b kfun:kotlinx.coroutines.JobSupport.tryMakeCompleting#internal + 755
at 11 KKit 0x103428d9b kfun:kotlinx.coroutines.JobSupport#makeCompletingOnce(kotlin.Any?){}kotlin.Any? + 379
at 12 KKit 0x10340953b kfun:kotlinx.coroutines.AbstractCoroutine#resumeWith(kotlin.Result<1:0>){} + 211
at 13 KKit 0x10339083b kfun:kotlin.coroutines.Continuation#resumeWith(kotlin.Result<1:0>){}-trampoline + 99
at 14 KKit 0x10326acbf kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 1163
at 15 KKit 0x10339083b kfun:kotlin.coroutines.Continuation#resumeWith(kotlin.Result<1:0>){}-trampoline + 99
at 16 KKit 0x10347376f kfun:kotlinx.coroutines.DispatchedTask#run(){} + 1691
at 17 KKit 0x1034a1d77 kfun:kotlinx.coroutines.Runnable#run(){}-trampoline + 91
at 18 KKit 0x1039ef357 kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.dispatch$lambda$1$lambda$0#internal + 475
at 19 KKit 0x1039f08bf kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.$dispatch$lambda$1$lambda$0$FUNCTION_REFERENCE$4.invoke#internal + 75
at 20 KKit 0x1039f09bb kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.$dispatch$lambda$1$lambda$0$FUNCTION_REFERENCE$4.$<bridge-UNN>invoke(){}#internal + 71
at 21 KKit 0x10338d167 kfun:kotlin.Function0#invoke(){}1:0-trampoline + 99
at 22 KKit 0x1039eec5f kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.performRun#internal + 319
at 23 KKit 0x1039ef4df kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.dispatch$lambda$1#internal + 239
at 24 KKit 0x1039f036b kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.$dispatch$lambda$1$FUNCTION_REFERENCE$0.invoke#internal + 139
at 25 KKit 0x103390e3f kfun:kotlin.Function2#invoke(1:0;1:1){}1:2-trampoline + 115
at 26 KKit 0x10326deab kfun:kotlin.coroutines.intrinsics.object-4.invokeSuspend#internal + 731
at 27 KKit 0x10339075b kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#invokeSuspend(kotlin.Result<kotlin.Any?>){}kotlin.Any?-trampoline + 67
at 28 KKit 0x10326aaa3 kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 623
at 29 KKit 0x10339083b kfun:kotlin.coroutines.Continuation#resumeWith(kotlin.Result<1:0>){}-trampoline + 99
at 30 KKit 0x10347382b kfun:kotlinx.coroutines.DispatchedTask#run(){} + 1879
at 31 KKit 0x1034a1d77 kfun:kotlinx.coroutines.Runnable#run(){}-trampoline + 91
at 32 KKit 0x10349d95f kfun:kotlinx.coroutines.DarwinMainDispatcher.dispatch$lambda$0#internal + 67
at 33 KKit 0x10349dbdb kfun:kotlinx.coroutines.DarwinMainDispatcher.$dispatch$lambda$0$FUNCTION_REFERENCE$1.invoke#internal + 71
at 34 KKit 0x10349dcab kfun:kotlinx.coroutines.DarwinMainDispatcher.$dispatch$lambda$0$FUNCTION_REFERENCE$1.$<bridge-UNN>invoke(){}#internal + 71
at 35 KKit 0x10338d167 kfun:kotlin.Function0#invoke(){}1:0-trampoline + 99
at 36 KKit 0x10349ebef _6f72672e6a6574627261696e732e6b6f746c696e783a6b6f746c696e782d636f726f7574696e65732d636f72652f6f70742f6275696c644167656e742f776f726b2f343465633665383530643563363366302f6b6f746c696e782d636f726f7574696e65732d636f72652f6e617469766544617277696e2f7372632f44697370617463686572732e6b74_knbridge13 + 191
at 37 libdispatch.dylib 0x180170103 _dispatch_call_block_and_release + 23
at 38 libdispatch.dylib 0x180171977 _dispatch_client_callout + 15
at 39 libdispatch.dylib 0x1801807c7 _dispatch_main_queue_drain + 1275
at 40 libdispatch.dylib 0x1801802bb _dispatch_main_queue_callback_4CF + 39
at 41 CoreFoundation 0x18040e95f __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 11
at 42 CoreFoundation 0x180409077 __CFRunLoopRun + 1935
at 43 CoreFoundation 0x1804084d3 CFRunLoopRunSpecific + 571
at 44 GraphicsServices 0x18ef2aae3 GSEventRunModal + 159
at 45 UIKitCore 0x1853d0a27 -[UIApplication _run] + 867
at 46 UIKitCore 0x1853d46af UIApplicationMain + 123
at 47 SwiftUI 0x1ccf100e3 OUTLINED_FUNCTION_65 + 491
at 48 SwiftUI 0x1ccf0ff8b OUTLINED_FUNCTION_65 + 147
at 49 SwiftUI 0x1ccbcd6d7 OUTLINED_FUNCTION_0 + 91
at 50 KKit 0x1028a4fb7 $s4KKit6iOSAppV5$mainyyFZ + 39
at 51 KKit 0x1028a5067 main + 11 (/Users/telephone/Code/KKit/iosApp/iosApp/iOSApp.swift:<unknown>)
at 52 dyld 0x105965543 0x0 + 4388705603
at 53 ??? 0x105a3a0df 0x0 + 4389576927
at 54 ??? 0xe544ffffffffffff 0x0 + -1926133265631019009
Any minimal code snippet to reproduce it? Does this only happen on iOS? Have you tried to increase maxStackSize to a larger number?
If this still only happens on iOS, it might be a bug I can't solve on Windows.
how to set maxStackSize?
You can try:
quickJs.maxStackSize = 512 * 1024 // Or something larger, defaults to 256 KB
It works! But I am quite worried is it abnormal to exhaust the default stack size?
I'm not familiar with quickjs's stack size but I think this is okay, Zipline also uses a large stack size (6 MB): https://github.com/cashapp/zipline/blob/55aa20f5b4cdae3753e92535afe41c670f851b1a/zipline/src/hostMain/kotlin/app/cash/zipline/Zipline.kt#L202