fix: NotificationChannelGroup crash (WPB-6233) #2687
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's new in this PR?
Issues
crash:
https://play.google.com/console/u/2/developers/7098984309886892484/app/4973241010395499500/vitals/crashes/cb7ccba8c13d0a497df6edf45962bb4f/details?days=7&isUserPerceived=true
Causes (Optional)
Logs says that app is trying to create a NotifcationChannel in a NotifcationChannelGroup that doesn't exist. This looks strange as we create Group first and only after it create channels in that group.
So it's hard to reproduce the crash.
From the logs in DataDog found out that at least some part of the crashes happens after logout.
AND deleting the NotifcationChannelGroup is called from a few places (basically on logout) and launched in a separate CoroutineScope.
So there is a theory that when user logs out,
GlobalObserversManager.setUpNotifications
gets invalid data first (list of users with logged out user) and after some time - valid data. This makes the app create notification group and channels for the user who is logged out. And somewhere during this in another CoroutineScopedeleteNotificationChannelGroup
is called.Solutions
Move calling
deleteNotificationChannelGroup
into the same CoroutineScope to escape such conflicts.For that update
NotificationChannelsManager.createUserNotificationChannels
to not just create Groups and Channels for "active" users, but also remove the Groups and Channels that don't belong to any "active" user.