Skip to content

QuickJS instance leaks after TreehouseApp.close() #2897

@adevone

Description

@adevone

Reproduction steps:

  1. Download the reproducer QuickJS leak reproducer #2896
  2. Launch the treehouse dev server of the example ./gradlew :samples:emoji-search:presenter-treehouse:serveDevelopmentZipline
  3. Use the 'Open' and back buttons on the iOS treehouse example (samples/emoji-search/ios-uikit) to create and close several instances of TreehouseApp

Probable cause of the leak:

RealTreehouseApp.close indirectly schedules a resource unloading coroutine on dispatchers.zipline (RealTreehouseApp.stop -> CodeHost.stop -> CodeSession.stop). It starts working because of CoroutineStart.ATOMIC strategy but then crashes in ZiplineScope.close.

This exception can be seen by adding a breakpoint to CodeSession.handleUncaughtException:

java.lang.IllegalStateException: Zipline closed
	at app.cash.zipline.Zipline$endpoint$1.call(Zipline.kt:64)
	at app.cash.zipline.internal.bridge.OutboundCallHandler.callInternal$zipline_release(OutboundCallHandler.kt:116)
	at app.cash.zipline.internal.bridge.OutboundCallHandler.call(OutboundCallHandler.kt:75)
	at app.cash.redwood.treehouse.AppLifecycle$Companion$Adapter$GeneratedOutboundService.close(AppLifecycle.kt:26)
	at app.cash.zipline.ZiplineScope.close(ZiplineScope.kt:93)
	at app.cash.redwood.treehouse.ZiplineCodeSession.ziplineStop(ZiplineCodeSession.kt:73)
	at app.cash.redwood.treehouse.CodeSession$stop$1.invokeSuspend(CodeSession.kt:85)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:34)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
  	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1156)
  	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:651)
  	at java.lang.Thread.run(Thread.java:1119)

The reproducer contains a probable fix of the leak on Android but it doesn't help on iOS.

Leak on iOS:

Screenshot 2025-11-22 at 21 15 38

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions