ARK-Builders / ARK-Navigator

Android app for navigation through your data
MIT License
15 stars 15 forks source link

ResourcesIndex isn't thread-safe #286

Closed mdrlzy closed 2 years ago

mdrlzy commented 2 years ago

Somehow 2 coroutines tried to reindex the root in parallel. The first one removed the missing resources from the map, the second one also tried to remove the same resources, which led to a crash.

07-23 16:44:41.790 D/resources-index(24397): 8 absent, 0 updated, 11 added
07-23 16:44:41.790 D/resources-index(24397): 8 absent, 0 updated, 11 added
07-23 16:44:41.792 D/resources-index(24397): deleting 8 resources from RAM and previews
07-23 16:44:41.792 D/resources-index(24397): deleting 8 resources from RAM and previews
07-23 16:44:41.800 D/resources-index(24397): deleting 8 resources from Room DB
07-23 16:44:41.800 D/resources-index(24397): splitting into 1 chunks
07-23 16:44:41.807 E/ACRA    (24397): ACRA caught a NullPointerException for space.taran.arknavigator
07-23 16:44:41.807 E/ACRA    (24397): java.lang.NullPointerException
07-23 16:44:41.807 E/ACRA    (24397):   at space.taran.arknavigator.mvp.model.repo.index.PlainResourcesIndex$reindexRoot$2.invokeSuspend(PlainResourcesIndex.kt:114)
07-23 16:44:41.807 E/ACRA    (24397):   at space.taran.arknavigator.mvp.model.repo.index.PlainResourcesIndex$reindexRoot$2.invoke(Unknown Source:8)
07-23 16:44:41.807 E/ACRA    (24397):   at space.taran.arknavigator.mvp.model.repo.index.PlainResourcesIndex$reindexRoot$2.invoke(Unknown Source:4)
07-23 16:44:41.807 E/ACRA    (24397):   at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
07-23 16:44:41.807 E/ACRA    (24397):   at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:165)
07-23 16:44:41.807 E/ACRA    (24397):   at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1)
07-23 16:44:41.807 E/ACRA    (24397):   at space.taran.arknavigator.mvp.model.repo.index.PlainResourcesIndex.reindexRoot$app_release(PlainResourcesIndex.kt:108)
07-23 16:44:41.807 E/ACRA    (24397):   at space.taran.arknavigator.mvp.model.repo.index.PlainResourcesIndex$reindex$2.invokeSuspend(PlainResourcesIndex.kt:72)
07-23 16:44:41.807 E/ACRA    (24397):   at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
07-23 16:44:41.807 E/ACRA    (24397):   at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
07-23 16:44:41.807 E/ACRA    (24397):   at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
07-23 16:44:41.807 E/ACRA    (24397):   at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
07-23 16:44:41.807 E/ACRA    (24397):   at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
07-23 16:44:41.807 E/ACRA    (24397):   at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)