Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 21, 2024

Conversation

kaioni17
Copy link
Contributor

@kaioni17 kaioni17 commented Nov 5, 2024

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
Copy link

codecov bot commented Nov 7, 2024

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:

Copy link
Member

@akarnokd akarnokd left a comment

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
Copy link
Contributor Author

kaioni17 commented Nov 9, 2024

Thanks for the review!

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