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

2.x: fix Single.timeout unnecessary dispose calls #5586

Merged
merged 2 commits into from Sep 10, 2017

Conversation

akarnokd
Copy link
Member

@akarnokd akarnokd commented Sep 6, 2017

This PR fixes the unnecessary dispose call towards the main source when the source terminates and reworks the internals to use less allocation and indirection.

@akarnokd akarnokd added this to the 2.2 milestone Sep 6, 2017
@codecov
Copy link

codecov bot commented Sep 6, 2017

Codecov Report

Merging #5586 into 2.x will increase coverage by 0.08%.
The diff coverage is 97.72%.

Impacted file tree graph

@@             Coverage Diff              @@
##                2.x    #5586      +/-   ##
============================================
+ Coverage     96.15%   96.23%   +0.08%     
- Complexity     5827     5828       +1     
============================================
  Files           632      632              
  Lines         41459    41467       +8     
  Branches       5742     5745       +3     
============================================
+ Hits          39863    39904      +41     
+ Misses          638      618      -20     
+ Partials        958      945      -13
Impacted Files Coverage Δ Complexity Δ
...tivex/internal/operators/single/SingleTimeout.java 98.27% <97.72%> (+2.27%) 2 <1> (ø) ⬇️
.../io/reactivex/internal/functions/ObjectHelper.java 94.73% <0%> (-5.27%) 20% <0%> (-1%)
...vex/internal/operators/single/SingleTakeUntil.java 91.8% <0%> (-3.28%) 2% <0%> (ø)
...tivex/internal/schedulers/TrampolineScheduler.java 92.3% <0%> (-2.57%) 6% <0%> (ø)
...activex/internal/observers/QueueDrainObserver.java 61.53% <0%> (-2.57%) 12% <0%> (-1%)
.../io/reactivex/disposables/CompositeDisposable.java 97.24% <0%> (-1.84%) 39% <0%> (-1%)
...java/io/reactivex/processors/PublishProcessor.java 98.29% <0%> (-1.71%) 45% <0%> (-1%)
...rnal/subscriptions/DeferredScalarSubscription.java 98.46% <0%> (-1.54%) 28% <0%> (-1%)
...vex/internal/operators/flowable/FlowableCache.java 92.61% <0%> (-1.35%) 7% <0%> (ø)
...perators/single/SingleFlatMapIterableFlowable.java 96.66% <0%> (-0.84%) 2% <0%> (ø)
... and 21 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 c43229b...75b425d. Read the comment docs.

Copy link
Contributor

@artem-zinnatullin artem-zinnatullin left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, but few comments

if (d != DisposableHelper.DISPOSED && compareAndSet(d, DisposableHelper.DISPOSED)) {
DisposableHelper.dispose(task);
actual.onError(e);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we deliver error to RxJavaPlugins.onError() in else block?

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed. Fixed.

if (other == null) {
actual.onError(new TimeoutException());
} else {
this.other = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, are you trying to avoid memory leak here? Reference to other is still held as a final field in SingleTimeout

I mean, final reference to other in TimeoutMainObserver will make code slightly more readable

Copy link
Member Author

Choose a reason for hiding this comment

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

The outer class has to reference other because of multiple subscribers. The inner observer has no use to the other once it has switched to it. There was an issue that some time ago that other was some cached resource that didn't go away when the user wanted it. This will somewhat help in that situation.


@Test
public void normalSuccessDoesntDisposeMain() {
final int[] calls = { 0 };
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I know you often use arrays for that, but AtomicInteger kinda much more readable when you need a reference to single "mutable" int :)

@akarnokd akarnokd merged commit 9b037c7 into ReactiveX:2.x Sep 10, 2017
@akarnokd akarnokd deleted the SingleTimeoutDisposeFix branch September 10, 2017 11:35
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.

None yet

3 participants