Skip to content

Conversation

@mattcreaser
Copy link
Member

@mattcreaser mattcreaser commented Sep 5, 2025

  • PR title and description conform to Pull Request guidelines.

Issue #, if available:

Description of changes:

  • Use onSubscription instead of onStart to trigger state machine events while collecting. onStart does not guarantee that emissions generated from the block are visible in downstream collectors when used on a SharedFlow.
  • Use SharedFlow for emitting states instead of a StateFlow because StateFlow will conflate emitted values, which can skip required intermediate states in subscribers.

These changes shouldn't effect production behaviour, but in unit tests this resolves some race conditions that happened when states update too quickly.

How did you test these changes?

  • Tests should pass

Documentation update required?

  • No
  • Yes (Please include a PR link for the documentation update)

General Checklist

  • Added Unit Tests
  • Added Integration Tests
  • Security oriented best practices and standards are followed (e.g. using input sanitization, principle of least privilege, etc)
  • Ensure commit message has the appropriate scope (e.g fix(storage): message, feat(auth): message, chore(all): message)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@mattcreaser mattcreaser requested a review from a team as a code owner September 5, 2025 14:36
StateFlow always conflates state updates, meaning it is possible for state updates to be missed by subscribers if they happen too fast. The only known case of this being possible was in DeleteUserUseCase. Using a SharedFlow we can avoid conflation and ensure all updates are delivered to subscribers.
@mattcreaser mattcreaser force-pushed the mattcreaser/flow-races branch from 99a0066 to 39247a7 Compare September 10, 2025 18:29
@codecov
Copy link

codecov bot commented Sep 10, 2025

Codecov Report

❌ Patch coverage is 94.28571% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.25%. Comparing base (0440ba3) to head (39247a7).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3126      +/-   ##
==========================================
- Coverage   54.26%   54.25%   -0.01%     
==========================================
  Files        1040     1040              
  Lines       32062    32071       +9     
  Branches     4712     4712              
==========================================
+ Hits        17398    17400       +2     
- Misses      12826    12828       +2     
- Partials     1838     1843       +5     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mattcreaser mattcreaser changed the title fix(auth): Fix race conditions in read state machine states chore(auth): Fix race conditions in read state machine states Sep 10, 2025
@mattcreaser mattcreaser merged commit 7fce116 into main Sep 10, 2025
17 of 18 checks passed
@mattcreaser mattcreaser deleted the mattcreaser/flow-races branch September 10, 2025 19:46
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.

2 participants