android-fhir icon indicating copy to clipboard operation
android-fhir copied to clipboard

Inaccurate tracking of SyncJobStatus due to "completion-event" preceding room db update

Open MJ1998 opened this issue 7 months ago • 0 comments

Describe the bug In FhirSynchronizer we do setState before syncDownload syncs resources in the local room database. This poses a critical issue as the SyncJobStatus should only be emitted or considered complete once the associated resources have been successfully updated in the Room database.

Component Engine library

To Reproduce Steps to reproduce the behavior:

  1. To simulate db transaction failure, add following lines
delay(1000)
throw RuntimeException("Simulated transaction failure")

inside syncDownload API before inserting synced resources. 2. Observe SyncJobState.InProgress(DOWNLOAD, total, completed = 1) where completed value is incorrect as db transaction failed.

Expected behavior SyncJobState should be emitted only when the resource in response is synced with local room db.

Screenshots If applicable, add screenshots to help explain your problem.

Smartphone (please complete the following information):

  • Device: [e.g. Pixel4a emulator]
  • Android version: [e.g. Settings -> About phone -> Android version]
  • Build number: [e.g. Settings -> About phone -> Build number]
  • Version [e.g. 22]

Additional context Maybe syncDownload API can return a Flow of some SyncState similar to uploadSync. These can be collected by the synchronizer and then SyncJobState can be persisted.

Alternatively,

Would you like to work on the issue? Please state if this issue should be assigned to you or who you think could help to solve this issue.

MJ1998 avatar Dec 11 '23 01:12 MJ1998