Skip to content

fix: Fix network check race condition#2888

Merged
FabianDevel merged 2 commits intomainfrom
fix-race-condition-on-network-check
Apr 29, 2026
Merged

fix: Fix network check race condition#2888
FabianDevel merged 2 commits intomainfrom
fix-race-condition-on-network-check

Conversation

@LouisCAD
Copy link
Copy Markdown
Contributor

In some cases, the hasNetwork property was read on isNetworkAvailable emission before it was set.

It was also much more likely to happen since the flow was activated twice. Now it's shared, and we read the value from a single place.

In some cases, the hasNetwork property was read on isNetworkAvailable emission before it was set.

It was also much more likely to happen since the flow
was activated twice. Now it's shared, and we read the value from a single place.
Copilot AI review requested due to automatic review settings April 29, 2026 13:18
@LouisCAD LouisCAD enabled auto-merge April 29, 2026 13:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a race where hasNetwork could be read before being updated from the isNetworkAvailable flow by turning network availability into a single shared StateFlow source of truth in MainViewModel.

Changes:

  • Convert isNetworkAvailable into a StateFlow via stateIn(...) to ensure one shared upstream collection.
  • Replace the mutable hasNetwork field with a value derived directly from isNetworkAvailable.value.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt
Comment thread app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt Outdated
@sonarqubecloud
Copy link
Copy Markdown

@FabianDevel FabianDevel disabled auto-merge April 29, 2026 13:43
@FabianDevel FabianDevel enabled auto-merge April 29, 2026 13:43
@FabianDevel FabianDevel merged commit 3b43e2f into main Apr 29, 2026
6 of 8 checks passed
@FabianDevel FabianDevel deleted the fix-race-condition-on-network-check branch April 29, 2026 13:43
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.

3 participants