Skip to content

Commit

Permalink
Do not query guest version from UI thread (#1949)
Browse files Browse the repository at this point in the history
I'm not sure how I ended up committing the previous version as I was making changes specifically to avoid this, but I did. Instead, read the version once on startup when the app lifecycle is first bound and cache its value for later access on the UI thread.
  • Loading branch information
JakeWharton authored Apr 9, 2024
1 parent 6f5dacf commit c15b9ed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Changed:

Fixed:
- Work around a problem with our memory-leak fix where our old LazyList code would crash when its placeholders were unexpectedly removed.
- Avoid calling into the internal Zipline instance from the UI thread on startup. This would manifest as weird native crashes due to multiple threads mutating shared memory.


## [0.10.0] - 2024-04-05
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import app.cash.zipline.Zipline
import app.cash.zipline.ZiplineApiMismatchException
import app.cash.zipline.ZiplineScope
import app.cash.zipline.withScope
import kotlin.concurrent.Volatile
import kotlinx.coroutines.CoroutineScope
import kotlinx.serialization.json.Json

Expand All @@ -37,22 +38,26 @@ internal class ZiplineCodeSession<A : AppService>(
appService = appService,
) {
private val ziplineScope = ZiplineScope()
private lateinit var appLifecycle: AppLifecycle

override val json: Json
get() = zipline.json

override val guestProtocolVersion: RedwoodVersion
get() {
return try {
appLifecycle.guestProtocolVersion
} catch (_: ZiplineApiMismatchException) {
RedwoodVersion.Unknown
}
@Volatile
private var _guestProtocolVersion: RedwoodVersion? = null

override val guestProtocolVersion: RedwoodVersion get() =
checkNotNull(_guestProtocolVersion) {
"Cannot access guest version before ziplineStart"
}

override fun ziplineStart() {
appLifecycle = appService.withScope(ziplineScope).appLifecycle
val appLifecycle = appService.withScope(ziplineScope).appLifecycle

_guestProtocolVersion = try {
appLifecycle.guestProtocolVersion
} catch (_: ZiplineApiMismatchException) {
RedwoodVersion.Unknown
}

val host = RealAppLifecycleHost(
appLifecycle = appLifecycle,
Expand Down

0 comments on commit c15b9ed

Please sign in to comment.