Page MenuHomePhabricator

[native] Stop calling saveMessageInfos from androidBackgroundMessageTask
ClosedPublic

Authored by ashoat on Nov 18 2022, 5:16 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Dec 23, 6:49 AM
Unknown Object (File)
Mon, Dec 23, 6:49 AM
Unknown Object (File)
Mon, Dec 23, 6:49 AM
Unknown Object (File)
Mon, Dec 23, 6:47 AM
Unknown Object (File)
Fri, Dec 20, 11:26 PM
Unknown Object (File)
Fri, Dec 20, 11:02 AM
Unknown Object (File)
Fri, Dec 20, 5:32 AM
Unknown Object (File)
Wed, Dec 11, 3:11 PM
Subscribers

Details

Summary

androidBackgroundMessageTask runs separately from the main app, and doesn't have any mechanisms in place to wait for redux-persist and SQLite before dispatching Redux actions.

The result of this is that the store can be messed up. See ENG-2275 for details on how this can happen.

This diff removes the saveMessageInfos call from handleAndroidMessage, which gets called in two scenarios. The first scenario is androidBackgroundMessageTask, and in that scenario we don't want to call saveMessageInfos. The second scenario is PushHandler.androidMessageReceived, and in that scenario we'll continue calling saveMessageInfos.

Since the only component we need to call saveMessageInfos from now is PushHandler, I also replaced the hacky dispatch import approach we were taking before in push/utils.js with a more idiomatic approach.

Test Plan

Confirm that issue in ENG-2275 no longer repros

Diff Detail

Repository
rCOMM Comm
Branch
ashoat/androidNotifIssue
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

It makes sense to remove saveMessageInfos here, since native code should handle updating SQLite when notifs are received while the app is closed.

On the other hand, we can't remove the other dispatches here (see inline comments) as easily. I don't feel great about having any dispatches in androidBackgroundMessageTask, since it feels like they could potentially result in the same type of issue.

That said, I don't think we will see the issue in ENG-2275 from these actions, since the only reducer that looks at them is native/push/reducer.js.

We also know that redux-persist won't try to save data until it has finished rehydrating, which means the only thing we need to worry about is how these dispatches will function if the data from SQLite (threadStore, messageStore, and draftStore) are missing. I think the actions I point out in the inline comments should not cause any problems in that scenario.

Of course, if redux-persist isn't persisting these dispatches (eg. because rehydrate has not concluded), that also implies that the dispatches are being ignored, which means that we may fail to properly rescind notifs that we are displaying.

The long-term solution here is to move all of this to C++.

native/push/android.js
32

We still have a dispatch here

71

And here

This definitely solves the issue – just confirmed with some additional testing with Reactotron.

Separately, from reading the code it seems like CommNotificationsHandler is already updating SQLite in the background when a notif comes in. Wanted to check with @tomek, is this assessment correct? (I haven't actually tested the code yet to confirm)

tomek added a subscriber: marcin.

This definitely solves the issue – just confirmed with some additional testing with Reactotron.

Separately, from reading the code it seems like CommNotificationsHandler is already updating SQLite in the background when a notif comes in. Wanted to check with @tomek, is this assessment correct? (I haven't actually tested the code yet to confirm)

It seems like we're accessing the db when a notif is received - I think that @marcin implemented that some time ago.

This revision is now accepted and ready to land.Nov 21 2022, 7:26 AM

Ah yeah, you're right – looking at blame, it looks like @marcin added the code to save rawMessageInfos from notifs to SQLite on Android via CommNotificationsHandler.

@marcin, wanted to get your confirmation here – is this code currently working? Part of my reasoning for thinking it's okay to get rid of the saveMessageInfos here is that it is already handled in CommNotificationsHandler, so I wanted to make sure that is true.

This revision now requires review to proceed.Nov 21 2022, 8:21 AM

Ah yeah, you're right – looking at blame, it looks like @marcin added the code to save rawMessageInfos from notifs to SQLite on Android via CommNotificationsHandler.

@marcin, wanted to get your confirmation here – is this code currently working? Part of my reasoning for thinking it's okay to get rid of the saveMessageInfos here is that it is already handled in CommNotificationsHandler, so I wanted to make sure that is true.

Yes, the code in CommNotificationsHandler is working and it is accessing database via GlobalDBSingleton so it is also safe.

This revision is now accepted and ready to land.Nov 21 2022, 10:18 AM