Hey, Can anyone help me with stackoverflow error i...
# squarelibraries
h
Hey, Can anyone help me with stackoverflow error in loadOnce method in Zipline
Copy code
suspend fun startReturning(context: Context): LoadResult {
        val ziplineLoader = ZiplineLoader (
            ziplineDispatcher,
            ManifestVerifier.NO_SIGNATURE_CHECKS, okHttpClient.asZiplineHttpClient() ).withCache(
            ZiplineCache(context, FileSystem.SYSTEM, context.cacheDir.toOkioPath(), 10*1024*1024)
        )
        val zipline = startGreetingZiplineReturning(
            ziplineLoader = ziplineLoader,
            manifestUrl = "<http://10.0.2.2:8080/manifest.zipline.json>"
        )
        return zipline
    }

    private suspend fun startGreetingZiplineReturning(
        ziplineLoader: ZiplineLoader,
        manifestUrl: String
    ): LoadResult {


        return ziplineLoader.loadOnce("<app-name>",
            DefaultFreshnessCheckerNotFresh, manifestUrl, initializer = { zipline: Zipline ->
            }
        )
    }
this is called as
Copy code
suspend fun invokeZiplineForResource(context: Context): ResourceService?{
        var resourceService : ResourceService? = null
        withContext(ziplineDispatcher) {
            try {
                val result = startReturning(context)
                resourceService = if (result is LoadResult.Success) {
                    result.zipline.take<ResourceService>("ResourceService")
                } else {
                    null
                }
            } catch (e: Exception) {
                e.printStackTrace()
            } finally {
                Log.e("zipline", resourceService.toString())
            }
        }
        return resourceService
    }
j
We’ve got fixes for this in Redwood that might fit you here. In Redwood we configure the threads that use Zipline to have larger stacks, because QuickJS likes big stacks
h
I am using the same size
j
Hmmm … does doubling it fix the problem?
h
I tried with 16
j
Ie. is this a problem with the algorithm or with the fixed limit?
Try 64?
I just wanna know if it’ll complete if the stack size is sufficient
Once you figure that out, you can go back to a smaller stack size by making the program slightly different
h
Trying now
j
Typically by finding calls that are done directly and replacing them with launches
h
Can
withContext(ziplineDispatcher)
be the issue instead of launching?
j
No, I was thinking specifically about launching in guest code
h
Failed with 64 too😢
j
It’s a QuickJS stack overflow?
h
yes
j
Can you try to print the stack before it crashes? Perhaps with the same strategy as the sampling profiler?
h
will try
j
QuickJs.interruptHandler = …
Copy code
override fun poll(): Boolean {
    val stack = quickJs.evaluate("new Error().stack") as String
    println(stack)
    return false
  }
That might tell you what the heck is happening when you’re using 64 MiB of stack
h
thanks
Hey @jessewilson, I have been trying to find how to set a quickJs instance to zipline. Did not find any way to set a quickJS instance to zipline. Can you please help me here too
j
It’s on the host API only
h
Didn't get that 🙂
The issue is related to kotlinx serialization json, the error got fixed on removing json elements from the server side and error changed to ClassCastException on making version same for kotlinx serialization core and kotlinx serialization json modules
j
Yay
h
Still have to figure out
ClassCastException
Assuming that the Zipline doesn't work well when the implementation includes Json. Abandoning using Json in my Service Implementation.
j
interesting