Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background sync is attempted even after user logs out #1210

Open
2 tasks
1t5j0y opened this issue Nov 30, 2023 · 1 comment
Open
2 tasks

Background sync is attempted even after user logs out #1210

1t5j0y opened this issue Nov 30, 2023 · 1 comment

Comments

@1t5j0y
Copy link
Contributor

1t5j0y commented Nov 30, 2023

Describe the bug
Background sync is triggered and fails behind the scenes if the user logs out while having unsynced items.

To Reproduce
Steps to reproduce the behavior:

  1. Login to the Avni app
  2. Let sync complete
  3. Perform a registration/encounter
  4. Logout without syncing
  5. Every hour background sync will be attempted and will fail (and will notify bugsnag).

Expected behavior
Background sync should not occur when user is logged out.

Additional context
Current logic only checks if userId is set or not which works if user has never logged in but does not work if user has logged in once and then logs out.

We should probably modify the code so that the job itself is only scheduled after login and cancelled on logout instead of relying on other states.

Logs
This was a case of an encounter with media.

 INFO  [7:37:12:445] [Sync][Info] Starting background sync
 INFO  [7:37:12:448] [Sync][Info] Starting SyncService
 INFO  [7:37:12:448] [Sync][Info] Getting SyncService
 DEBUG  [7:37:12:449] [BaseService][Debug] Dispatching action: "SYNC.ON_BACKGROUND_SYNC_STATUS_CHANGE"
 INFO  [7:37:12:450] [Sync][Info] Getting connection info
 INFO  [7:37:12:452] [Sync][Info] Calling syncService.sync
 DEBUG  [7:37:12:452] [SyncService][Debug] sync
 DEBUG  [7:37:12:459] [BaseService][Debug] Dispatching action: "SyncTelemetryActions.START_SYNC"
 DEBUG  [7:37:12:463] [mediaUploadRequired][Debug] true
 DEBUG  [7:37:12:465] [BaseService][Debug] Dispatching action: "SYNC.ON_BACKGROUND_SYNC_STATUS_CHANGE"
 DEBUG  [7:37:12:467] [MediaQueueService][Debug] Number of media queue items: 2
 INFO  [7:37:12:467] [MediaQueueService][Info] Upload batch size 1
 DEBUG  [7:37:12:468] [FileSystem][Debug] /storage/emulated/0/Android/data/com.openchsclient/files/Avni/media/images/
 DEBUG  [7:37:12:470] [Requests][Debug] Calling getText: https://staging.avniproject.org/media/uploadUrl/755e8b5c-8017-496d-b0a1-1c56cd2d5e37.jpg
 ERROR  MediaQueueService undefined, "Error while uploading f3edf5d1-ef83-491f-a78c-ed47fa2f164b - 755e8b5c-8017-496d-b0a1-1c56cd2d5e37.jpg"
 ERROR  MediaQueueService No user or needs login, {"authErrCode":"No User","authErrDate":"2023-11-29T02:07:12.475Z"} Error: No user or needs login
    at AuthenticationError (http://10.0.2.2:8081/index.android.bundle//&platform=android&dev=true&minify=false&app=com.openchsclient&modulesOnly=false&runModule=true:193185:29)
    at anonymous (http://10.0.2.2:8081/index.android.bundle//&platform=android&dev=true&minify=false&app=com.openchsclient&modulesOnly=false&runModule=true:193684:56)
    at tryCallOne (/root/react-native/packages/react-native/ReactAndroid/hermes-engine/.cxx/Release/4i495j47/x86/lib/InternalBytecode/InternalBytecode.js:53:16)
    at anonymous (/root/react-native/packages/react-native/ReactAndroid/hermes-engine/.cxx/Release/4i495j47/x86/lib/InternalBytecode/InternalBytecode.js:139:27)
    at apply (native)
    at anonymous (http://10.0.2.2:8081/index.android.bundle//&platform=android&dev=true&minify=false&app=com.openchsclient&modulesOnly=false&runModule=true:39142:26)
    at _callTimer (http://10.0.2.2:8081/index.android.bundle//&platform=android&dev=true&minify=false&app=com.openchsclient&modulesOnly=false&runModule=true:39021:17)
    at _callReactNativeMicrotasksPass (http://10.0.2.2:8081/index.android.bundle//&platform=android&dev=true&minify=false&app=com.openchsclient&modulesOnly=false&runModule=true:39066:17)
    at callReactNativeMicrotasks (http://10.0.2.2:8081/index.android.bundle//&platform=android&dev=true&minify=false&app=com.openchsclient&modulesOnly=false&runModule=true:39272:44)
    at __callReactNativeMicrotasks (http://10.0.2.2:8081/index.android.bundle//&platform=android&dev=true&minify=false&app=com.openchsclient&modulesOnly=false&runModule=true:3206:46)
    at anonymous (http://10.0.2.2:8081/index.android.bundle//&platform=android&dev=true&minify=false&app=com.openchsclient&modulesOnly=false&runModule=true:2980:45)
    at __guard (http://10.0.2.2:8081/index.android.bundle//&platform=android&dev=true&minify=false&app=com.openchsclient&modulesOnly=false&runModule=true:3179:15)
    at flushedQueue (http://10.0.2.2:8081/index.android.bundle//&platform=android&dev=true&minify=false&app=com.openchsclient&modulesOnly=false&runModule=true:2979:21)
    at invokeCallbackAndReturnFlushedQueue (http://10.0.2.2:8081/index.android.bundle//&platform=android&dev=true&minify=false&app=com.openchsclient&modulesOnly=false&runModule=true:2973:33)
 DEBUG  [7:37:12:483] [ErrorHandler][Debug] IsFatal=true Error: syncTimeoutError
 DEBUG  [7:37:12:483] [ErrorHandler][Debug] syncTimeoutError
 DEBUG  [7:37:12:491] [ErrorHandler][Debug] Creating frame array
 DEBUG  [7:37:12:491] [ErrorHandler][Debug] Notifying Bugsnag Error: Fatal error: syncTimeoutError
 WARN  Possible Unhandled Promise Rejection (id: 2):
Error: Fatal error: syncTimeoutError
Error: Fatal error: syncTimeoutError

Developer Checklist
Developer fixing the bug should fill this checklist.

  • Does the fix require extensive regression testing?
  • Are you mentioning the required scenarios that could be affected?
@1t5j0y 1t5j0y converted this from a draft issue Nov 30, 2023
@1t5j0y
Copy link
Contributor Author

1t5j0y commented Nov 30, 2023

This should explain the large number of bugsnag occurrences with undefined users in #1196

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New Issues
Development

No branches or pull requests

1 participant