Skip to content

Declare the mute durations before the settings view model's init - #2274

Draft
mpretty-cyro wants to merge 1 commit into
session-foundation:devfrom
mpretty-cyro:fix/notification-settings-init-order
Draft

mpretty-cyro wants to merge 1 commit into
session-foundation:devfrom
mpretty-cyro:fix/notification-settings-init-order

Conversation

@mpretty-cyro

Copy link
Copy Markdown
Collaborator

Contributor checklist

  • I have tested my contribution on these devices:
  • Virtual device: Pixel 6 profile, API 37 (arm64), play flavour, qa
  • My contribution is fully baked and ready to be merged as is
  • I ensure that all the open issues my contribution fixes are mentioned in the commit message of my first commit using the Fixes #1234 syntax

Description

Crash cluster in 1.33.9: NullPointerException in NotificationSettingsViewModel.updateState mapping muteDurations (6 users / 6 events). The code is unchanged since before 1.33.7.

The init block starts collecting the recipient on Dispatchers.Default, and the first emission can call updateState before the constructor has run the initialisers of properties declared after init. For a muted conversation updateState builds the mute options from muteDurations, which was declared at the bottom of the class and could still be null. Moving muteDurations and debugMuteDurations above init makes them initialised before the collector starts. Nothing else is changed.

Confidence: high.

Testing: muted a 1:1 conversation for an hour, then opened its notification settings eleven times. Each time it showed "Muted until …" and the full list of mute durations, with no crash. The race itself, the collector winning against the constructor, was not reproduced.

The init block's collector runs on Dispatchers.Default and can reach
updateState before the constructor initialises properties declared after
it, so opening notification settings for a muted conversation could read
a null muteDurations and crash.

@mpretty-cyro mpretty-cyro left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant