Skip to content

Update BlockingFlowableIterable.onNext() to set error before cancel - #7789

Merged
akarnokd merged 1 commit into
ReactiveX:3.xfrom
kaioni17:3.x
Nov 21, 2024
Merged

akarnokd merged 1 commit into
ReactiveX:3.xfrom
kaioni17:3.x

Conversation

@kaioni17

@kaioni17 kaioni17 commented Nov 5, 2024

Copy link
Copy Markdown
Contributor

To avoid race with hasNext(), which checks for cancel first before checking for error. For example, in the following case, hasNext() may return false to the caller, making the caller assume the iterable finished successfully.

  1. onNext() called cancel
  2. hasNext() found the iterable is cancelled
  3. hasNext() found that error is null thus returned false to the caller, without throwing the error
  4. onNext() set error

It's a bit hard to test this race condition in unit tests. Existing tests can make sure no regression is introduced.

To avoid race with hasNext(), which checks for cancel first before checking for error. For example, in the following case, hasNext() may return false to the caller, making the caller assume the iterable finished successfully.
1. onNext() called cancel
2. hasNext() found the iterable is cancelled
3. hasNext() found that error is null thus returned false to the caller, without throwing the error
4. onNext() set error
@codecov

codecov Bot commented Nov 7, 2024 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.62%. Comparing base (9b55d01) to head (e526cc3).
Report is 112 commits behind head on 3.x.

Additional details and impacted files
@@            Coverage Diff            @@
##                3.x    #7789   +/-   ##
=========================================
  Coverage     99.62%   99.62%           
  Complexity     6801     6801           
=========================================
  Files           752      752           
  Lines         47707    47711    +4     
  Branches       6401     6402    +1     
=========================================
+ Hits          47527    47532    +5     
+ Misses           84       81    -3     
- Partials         96       98    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@akarnokd akarnokd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for catching this.

@kaioni17

kaioni17 commented Nov 9, 2024

Copy link
Copy Markdown
Contributor Author

Thanks for the review!

@akarnokd
akarnokd merged commit 338f2a1 into ReactiveX:3.x Nov 21, 2024
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