colaorange / daily-money-one-doc

daily money one, issues
0 stars 0 forks source link

App Crashes When Returning to Foreground and Accessing Transaction List After Running in Background #30

Closed dennischen closed 5 months ago

dennischen commented 5 months ago

logcat.txt


2024-05-17 20:00:13.322 22591-22659 ReactNativeJS           com.colaorange.dailymoneyone         E  Error: Accessing object which has been invalidated or deleted

                                                                                                    This error is located at:
                                                                                                        in TransactionListScreen
                                                                                                        in RCTView
                                                                                                        in Unknown
                                                                                                        in ScreenContainer
                                                                                                        in StaticContainer
                                                                                                        in EnsureSingleNavigator
                                                                                                        in SceneView
                                                                                                        in RCTView
                                                                                                        in Unknown
                                                                                                        in DebugContainer
                                                                                                        in MaybeNestedStack
                                                                                                        in RCTView
                                                                                                        in Unknown
                                                                                                        in RNSScreen
                                                                                                        in Unknown
                                                                                                        in Suspender
                                                                                                        in Suspense
                                                                                                        in Freeze
                                                                                                        in DelayedFreeze
                                                                                                        in InnerScreen
                                                                                                        in Screen
                                                                                                        in SceneView
                                                                                                        in Suspender
                                                                                                        in Suspense
                                                                                                        in Freeze
                                                                                                        in DelayedFreeze
                                                                                                        in RNSScreenStack
                                                                                                        in ScreenStack
                                                                                                        in NativeStackViewInner
                                                                                                        in RCTView
                                                                                                        in Unknown
                                                                                                        in SafeAreaProviderCompat
                                                                                                        in NativeStackView
                                                                                                        in PreventRemoveProvider
                                                                                                        in NavigationContent
                                                                                                        in Unknown
                                                                                                        in NativeStackNavigator
                                                                                                        in EnsureSingleNavigator
                                                                                                        in BaseNavigationContainer
                                                                                                        in ThemeProvider
                                                                                                        in NavigationContainerInner
                                                                                                        in NavigationScreenContainer
                                                                                                        in PrimaryBookProvider
                                                                                                        in ProviderGroup3Container
                                                                                                        in StartTaskBoundary
                                                                                                        in PreferencesProvider
                                                                                                        in OnceProvider
                                                                                                        in ServicesProvider
                                                                                                        in DatabaseRestoreBoundary
                                                                                                        in ErrorReporterProvider
                                                                                                        in ProviderGroup2Container
                                                                                                        in ToolboxProvider
                                                                                                        in AlertProvider
                                                                                                        in ThemeProvider
                                                                                                        in RCTView
                                                                                                        in Unknown
                                                                                                        in Portal.Host
                                                                                                        in RCTView
                                                                                                        in Unknown
                                                                                                        in SafeAreaProviderCompat
                                                                                                        in PaperProvider
                                                                                                        in AppThemeProvider
                                                                                                        in EventQueueHolderProvider
                                                                                                        in I18nProvider
                                                                                                        in ProviderGroup1Container
                                                                                                        in RNGestureHandlerRootView
                                                                                                        in GestureHandlerRootView
                                                                                                        in RNCSafeAreaView
                                                                                                        in Unknown
                                                                                                        in RNCSafeAreaProvider
                                                                                                        in SafeAreaProvider
                                                                                                        in App
                                                                                                        in RCTView
                                                                                                        in Unknown
                                                                                                        in RCTView
                                                                                                        in Unknown
                                                                                                        in AppContainer, js engine: hermes```
dennischen commented 5 months ago

some more log today

----
## Start app after a long background idle
----
2024-05-19 09:03:26.756 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         I  '[DM]>', 'active', 'App State Changed from', 'background', 'to', 'active'

### The backgournd ia running in 'active' !! doesn't it should only run in background?

2024-05-19 09:03:27.067 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         I  '[DM]>', 'active', 'Start backupDatabaseTask call at time:', 'Sun May 19 2024 09:03:27 GMT+0800'
2024-05-19 09:03:27.119 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         I  '[DM]>', 'active', 'Opened realm', '/data/data/com.colaorange.dailymoneyone/files/daily-money-one.realm', 'active'
2024-05-19 09:03:27.435 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         I  '[DM]>', 'active', 'Start to backup database automatically, auto upload config to true'
2024-05-19 09:03:27.436 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         D  '[DM]>', 'active', 'Storage Uri', 'content://com.android.externalstorage.documents/tree/primary%3ADMO'
2024-05-19 09:03:27.436 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         D  '[DM]>', 'active', 'Use Backup Dir', 'content://com.android.externalstorage.documents/tree/primary%3ADMO'
2024-05-19 09:03:27.449 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         D  '[DM]>', 'active', 'New temp src to backup, size 723520', 'file:///data/user/0/com.colaorange.dailymoneyone/files/temp-backup.realm'
2024-05-19 09:03:27.535 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         D  '[DM]>', 'active', 'New dest backup', 'content://com.android.externalstorage.documents/tree/primary%3ADMO/document/primary%3ADMO%2Fauto-dmo-20240519-0903.db'
2024-05-19 09:03:27.636 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         D  '[DM]>', 'active', 'Copied temp backup from file:///data/user/0/com.colaorange.dailymoneyone/files/temp-backup.realm to content://com.android.externalstorage.documents/tree/primary%3ADMO/document/primary%3ADMO%2Fauto-dmo-20240519-0903.db'
2024-05-19 09:03:27.637 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         I  '[DM]>', 'active', 'Backed up to content://com.android.externalstorage.documents/tree/primary%3ADMO/document/primary%3ADMO%2Fauto-dmo-20240519-0903.db'
2024-05-19 09:03:33.125 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         I  '[DM]>', 'active', 'Uploaded auto-dmo-20240519-0903.db, size: 723520'
2024-05-19 09:03:33.176 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         D  '[DM]>', 'active', 'Start to prune older auto backup retentionCount: 30, retentionDays: 30'
2024-05-19 09:03:33.244 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         I  '[DM]>', 'active', 'End backupDatabaseTask call at time:', 'Sun May 19 2024 09:03:33 GMT+0800'

### although we close another realm instance, but it has same path as foreground realm. I think relam cache them by path
### so, the foreground realm will be closed too.

2024-05-19 09:03:33.247 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         I  '[DM]>', 'active', 'Closed Realm', '/data/data/com.colaorange.dailymoneyone/files/daily-money-one.realm'

------
## push app to background and start again.
------
2024-05-19 09:05:27.087 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         I  '[DM]>', 'background', 'App State Changed from', 'active', 'to', 'background'

### this message is form dataService, which detected state changed to active, it will check dataService isClosed

2024-05-19 09:06:02.400 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         I  '[DM]>', 'active', 'App State Changed from', 'background', 'to', 'active'
2024-05-19 09:06:02.403 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         W  '[DM]>', 'active', 'dataService isClosed for unknow reason when app re-activating, reset it'
2024-05-19 09:06:02.605 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         I  '[DM]>', 'active', 'Opened realm', '/data/data/com.colaorange.dailymoneyone/files/daily-money-one.realm', 'active'

### this message is from unscuscribe a previous foreground dataService

2024-05-19 09:06:02.608 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         I  '[DM]>', 'active', 'Realm is already closed'
2024-05-19 09:06:03.028 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         D  '[DM]>', 'active', 'Registered Task', { taskType: 'backgroundFetch',
                                                                                                      taskName: 'backupDatabaseTask',
                                                                                                      options: 
                                                                                                       { minimumInterval: 3600,
                                                                                                         stopOnTerminate: false,
                                                                                                         startOnBoot: true } }
2024-05-19 09:06:03.029 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         D  '[DM]>', 'active', 'backupDatabaseTask.syncBackgroundFetch'
2024-05-19 09:06:03.762 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         D  '[DM]>', 'active', 'report cost in v2 (quick)', 255
2024-05-19 09:06:04.153 10563-10640 ReactNativeJS           com.colaorange.dailymoneyone         D  '[DM]>', 'active', 'report cost in v2 (quick)', 16
dennischen commented 5 months ago

According to diagnosis #30, I found that realm instances are shared by path name (though there may be other conditions). Therefore, we need to count the number of create-close operations by path name to perform the actual close.

dennischen commented 5 months ago

fixed the issue by added realm instance shared counter mapping by pathname