JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
16.24k stars 1.18k forks source link

Skiko Cache Corruption: java.lang.UnsatisfiedLinkError: Can't load library #2895

Closed ScottPierce closed 1 month ago

ScottPierce commented 1 year ago

Describe the bug It seems that sometimes the skiko cache in ~/.skiko can become corrupted, and the user will become stuck, unable to open the app. The only fix is to get the user to delete the ~/.skiko directory. When this corruption happens, the app will not open, and nothing can be done.

It's unclear how this corruption happens, but I've seen it on at least 4 developers computers.

image
java.lang.UnsatisfiedLinkError: Can't load library: /Users/scottpierce/.skiko/9501f4ff87ab1f362914703c445352b4fa63ad64a4fa1677eebfb03ff03a0cde/libskiko-macos-arm64.dylib
    at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2393)
    at java.base/java.lang.Runtime.load0(Runtime.java:755)
    at java.base/java.lang.System.load(System.java:1953)
    at org.jetbrains.skiko.Library.loadLibraryOrCopy(Library.kt:20)
    at org.jetbrains.skiko.Library.findAndLoad(Library.kt:113)
    at org.jetbrains.skiko.Library.load(Library.kt:59)
    at org.jetbrains.skiko.SkiaLayer.<clinit>(SkiaLayer.awt.kt:32)
    at androidx.compose.ui.awt.ComposeLayer.<init>(ComposeLayer.desktop.kt:92)
    at androidx.compose.ui.awt.ComposeWindowDelegate.<init>(ComposeWindowDelegate.desktop.kt:59)
    at androidx.compose.ui.awt.ComposeWindow.<init>(ComposeWindow.desktop.kt:61)
    at androidx.compose.ui.awt.ComposeWindow.<init>(ComposeWindow.desktop.kt:59)
    at androidx.compose.ui.window.Window_desktopKt$Window$3.invoke(Window.desktop.kt:162)
    at androidx.compose.ui.window.Window_desktopKt$Window$3.invoke(Window.desktop.kt:156)
    at androidx.compose.ui.window.Window_desktopKt$Window$10$1.invoke(Window.desktop.kt:378)
    at androidx.compose.ui.window.Window_desktopKt$Window$10$1.invoke(Window.desktop.kt:377)
    at androidx.compose.ui.window.AwtWindow_desktopKt$AwtWindow$2.invoke(AwtWindow.desktop.kt:75)
    at androidx.compose.ui.window.AwtWindow_desktopKt$AwtWindow$2.invoke(AwtWindow.desktop.kt:74)
    at androidx.compose.runtime.DisposableEffectImpl.onRemembered(Effects.kt:81)
    at androidx.compose.runtime.CompositionImpl$RememberEventDispatcher.dispatchRememberObservers(Composition.kt:1091)
    at androidx.compose.runtime.CompositionImpl.applyChangesInLocked(Composition.kt:818)
    at androidx.compose.runtime.CompositionImpl.applyChanges(Composition.kt:839)
    at androidx.compose.runtime.Recomposer.composeInitial$runtime(Recomposer.kt:978)
    at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:519)
    at androidx.compose.ui.window.Application_desktopKt$awaitApplication$2$1$2.invokeSuspend(Application.desktop.kt:219)
    at kotlin.stdlib/kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:771)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:716)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:741)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

Affected platforms Select one of the platforms below:

Versions

To Reproduce

  1. Open app

Expected behavior In the case that the skiko cache becomes corrupted like this, skiko should catch the exception itself, and repair the cache automatically.

mikehearn commented 1 year ago

The actual cause of load failure here is almost certainly a signature mismatch, which can occur when shipping a JAR with a signed skiko inside. The error crops up now because Conveyor recently added support for this type of signing to help with other JVM libraries that need special configuration to load their JNI library from inside a bundle/installed app dir.

There's an explanation of the error in more depth here:

https://conveyor.hydraulic.dev/7.1/troubleshooting/troubleshooting-jvm/#unsatisfiedlinkerror-mapping-process-and-mapped-file-non-platform-have-different-team-ids

and a discussion of the overall ecosystem problems that lead to it here:

https://hydraulic.software/blog/11-in-jar-signing.html

There are many solutions, but from Compose's perspective probably the simplest is to catch a failure to load the library from ~/.skiko and delete/re-extract the dylib. That will make sure that whatever's on disk has a signature that matches the signer of the app itself at load time. It's ugly, especially if you have multiple Compose apps running at once, but it should work. The "real" solution here is always to turn on JNI library extraction at packaging time so there's no need for Compose or other libs to do this extract-to-home-dir dance at all. Compose is compatible with this out of the box, the problem is more other libraries and the general effort required to configure them all.

eymar commented 1 year ago

Related thread in Slack https://kotlinlang.slack.com/archives/C01D6HTPATV/p1679036069089779

okushnikov commented 2 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.