Skip to content

Commit 4aacc70

Browse files
committed
fix(android-sqlite): Use warm-up generation counter for stale run guard
1 parent 804f413 commit 4aacc70

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

  • sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/sqlite

sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/sqlite/SampleDatabases.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ object SampleDatabases {
5353
private set
5454

5555
@Volatile private var warmUpComplete = false
56+
@Volatile private var warmUpGeneration = 0
5657
@Volatile private var warmUpJob: Job? = null
5758

5859
fun isWarmUpComplete(): Boolean = warmUpComplete
@@ -259,6 +260,7 @@ object SampleDatabases {
259260
/** Opens every database on a background thread, forcing the one-time open + bootstrap to run. */
260261
fun warmUp(context: Context) {
261262
val appContext = context.applicationContext
263+
val generation = ++warmUpGeneration
262264
warmUpComplete = false
263265
warmUpErrors = ""
264266
// Fire-and-forget: the warm-up outlives no particular screen, so a bare scope is fine here.
@@ -289,8 +291,10 @@ object SampleDatabases {
289291
.countSongs()
290292
.executeAsOne()
291293
}
292-
warmUpErrors = failures.joinToString("\n") { "Warm-up failed: $it" }
293-
warmUpComplete = true
294+
if (generation == warmUpGeneration) {
295+
warmUpErrors = failures.joinToString("\n") { "Warm-up failed: $it" }
296+
warmUpComplete = true
297+
}
294298
}
295299
}
296300

0 commit comments

Comments
 (0)