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

3.x: Document Schedulers.from's RejectedExecutionException handling #7150

Merged
merged 1 commit into from
Jan 19, 2021

Conversation

akarnokd
Copy link
Member

Updates the 3 overloads of Schedulers.from to describe (in a concise manner) the cases when the Executor would throw a RejectedExecutionException. Such exceptions can't be reasonably handled from within RxJava.

There are typically two cases when such exception would occur:

  1. The underlying Executor is shut down.

Operators such as observeOn guarantee worker-confinement when calling onNext, onError and onComplete. A failure to schedule would at best bypass this confinement, notifying the downstream on the current thread, at worst cause overlapping execution downstream.

The recommended workaround is to cancel all flows using the particular Scheduler after which the Executor can be shut down safely.

  1. The underlying Executor temporarily rejects more work.

Such temporary rejections are often used in traditional Executor usages to drop work or pause the submission of work. In RxJava though, there is often no 1:1 correspondence to signals (onNext, onError or onComplete). Some work may be correlated to several onNexts, other work may be due to downstream requests. Dropping any such work may lead to inconsistent flow state or livelocks.

The recommended workaround is to express limits on the execution via backpressure (e.g., Flowables).

Resolves #7149

@akarnokd akarnokd added this to the 3.1 milestone Jan 17, 2021
@codecov
Copy link

codecov bot commented Jan 17, 2021

Codecov Report

Merging #7150 (fbb184d) into 3.x (54850d0) will decrease coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##                3.x    #7150      +/-   ##
============================================
- Coverage     99.55%   99.53%   -0.03%     
+ Complexity     6709     6706       -3     
============================================
  Files           745      745              
  Lines         47327    47327              
  Branches       6375     6375              
============================================
- Hits          47117    47106      -11     
- Misses           93      100       +7     
- Partials        117      121       +4     
Impacted Files Coverage Δ Complexity Δ
...va/io/reactivex/rxjava3/schedulers/Schedulers.java 100.00% <ø> (ø) 12.00 <0.00> (ø)
...ors/flowable/FlowableOnBackpressureReduceWith.java 88.00% <0.00%> (-12.00%) 2.00% <0.00%> (ø%)
.../operators/flowable/FlowableBlockingSubscribe.java 93.02% <0.00%> (-4.66%) 10.00% <0.00%> (-1.00%)
...xjava3/internal/observers/FutureMultiObserver.java 96.61% <0.00%> (-3.39%) 27.00% <0.00%> (-1.00%)
.../operators/observable/ObservableFlatMapSingle.java 94.44% <0.00%> (-3.18%) 2.00% <0.00%> (ø%)
...rnal/operators/flowable/FlowableFlatMapSingle.java 95.34% <0.00%> (-2.33%) 2.00% <0.00%> (ø%)
...o/reactivex/rxjava3/processors/AsyncProcessor.java 97.91% <0.00%> (-2.09%) 44.00% <0.00%> (-1.00%)
...va3/internal/operators/parallel/ParallelRunOn.java 98.52% <0.00%> (-1.48%) 8.00% <0.00%> (ø%)
...ternal/operators/observable/ObservableFlatMap.java 98.22% <0.00%> (-0.36%) 3.00% <0.00%> (ø%)
...ernal/operators/flowable/FlowableFlatMapMaybe.java 96.37% <0.00%> (ø) 2.00% <0.00%> (ø%)
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 54850d0...fbb184d. Read the comment docs.

@akarnokd akarnokd merged commit af297c4 into ReactiveX:3.x Jan 19, 2021
* because such circumstances prevent RxJava from progressing flow-related activities correctly.
* If the {@link Executor#execute(Runnable)} or {@link ExecutorService#submit(Callable)} throws,
* the {@code RejectedExecutionException} is routed to the global error handler via
* {@link RxJavaPlugins#onError(Throwable)}. To avoid shutdown-reladed problems, it is recommended
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be a typo?

shutdown-reladed problems

Copy link
Member Author

@akarnokd akarnokd Feb 2, 2021

Choose a reason for hiding this comment

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

Yep, typos. Would you like to fix them?

Copy link
Contributor

Choose a reason for hiding this comment

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

Here's the PR #7178.

* because such circumstances prevent RxJava from progressing flow-related activities correctly.
* If the {@link Executor#execute(Runnable)} or {@link ExecutorService#submit(Callable)} throws,
* the {@code RejectedExecutionException} is routed to the global error handler via
* {@link RxJavaPlugins#onError(Throwable)}. To avoid shutdown-reladed problems, it is recommended
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be a typo?

shutdown-reladed problems

* because such circumstances prevent RxJava from progressing flow-related activities correctly.
* If the {@link Executor#execute(Runnable)} or {@link ExecutorService#submit(Callable)} throws,
* the {@code RejectedExecutionException} is routed to the global error handler via
* {@link RxJavaPlugins#onError(Throwable)}. To avoid shutdown-reladed problems, it is recommended
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be a typo?

shutdown-reladed problems

@ShengChangYang ShengChangYang mentioned this pull request Feb 2, 2021
@akarnokd akarnokd deleted the SchedulersFromREE branch September 6, 2021 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2.x, 3.x RejectionExecutionException is not handled properly in FlowableObserveOn operator
4 participants