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

Fix a racing condition when subscribing to a completed ScopeProvider. #135

Closed
wants to merge 2 commits into from

Conversation

duanbo1983
Copy link

Description:

Related issue(s):

@CLAassistant
Copy link

CLAassistant commented Nov 15, 2017

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@duanbo1983 duanbo1983 closed this Nov 15, 2017
@duanbo1983 duanbo1983 reopened this Nov 16, 2017
@@ -55,6 +55,8 @@

@Override public void onComplete() {
callMainSubscribeIfNecessary(d);
Copy link
Author

@duanbo1983 duanbo1983 Nov 16, 2017

Choose a reason for hiding this comment

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

When subscribing to a completed ScopeProvider, callMainSubscribeIfNecessary() might be called here before the main source is subscribed, which triggers the DoubleSubscriptionsException.

@duanbo1983 duanbo1983 changed the title Fix a racing condition when subscribing a completed ScopeProvider. Fix a racing condition when subscribing to a completed ScopeProvider. Nov 16, 2017
@duanbo1983 duanbo1983 closed this Nov 16, 2017
@duanbo1983 duanbo1983 deleted the bo_racing_condition branch November 16, 2017 00:31
@duanbo1983 duanbo1983 restored the bo_racing_condition branch November 16, 2017 00:31
@duanbo1983 duanbo1983 reopened this Nov 16, 2017
RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
assertThat(throwable instanceof ProtocolViolationException).isFalse();
Copy link
Author

@duanbo1983 duanbo1983 Nov 16, 2017

Choose a reason for hiding this comment

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

This test case fails in master as:

Exception in thread "main" io.reactivex.exceptions.ProtocolViolationException: It is not allowed to subscribe with a(n) com.uber.autodispose.AutoDisposingObserverImpl multiple times. Please create a fresh instance of com.uber.autodispose.AutoDisposingObserverImpl and subscribe that to the target source instead.
	at com.uber.autodispose.AutoDisposeEndConsumerHelper.reportDoubleSubscription(AutoDisposeEndConsumerHelper.java:110)
	at com.uber.autodispose.AutoDisposeEndConsumerHelper.setOnce(AutoDisposeEndConsumerHelper.java:56)
	at com.uber.autodispose.AutoDisposingObserverImpl.onSubscribe(AutoDisposingObserverImpl.java:67)
	at io.reactivex.subjects.PublishSubject.subscribeActual(PublishSubject.java:85)
	at io.reactivex.Observable.subscribe(Observable.java:10842)
	at com.uber.autodispose.ObservableScoper$AutoDisposeObservable.subscribeActual(ObservableScoper.java:113)
	at io.reactivex.Observable.subscribe(Observable.java:10842)
	at com.uber.autodispose.ObservableScoper$1.subscribe(ObservableScoper.java:94)
	at com.uber.autodispose.AutoDisposeObserverTest.autoDispose_withScopeProviderCompleted_shouldNotReportDoubleSubscriptions(AutoDisposeObserverTest.java:192)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't quite understand this test, as the ProtocolViolationException isn't obvious. Some sort of comment and asserting what you do expect should happen here

It also won't fail if this callback isn't hit, let's make it explicit somehow that we expect this callback to be hit

Copy link
Collaborator

@ZacSweers ZacSweers left a comment

Choose a reason for hiding this comment

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

Good start. Can you also update the other observers? i.e. for Single, Maybe, Completable, and Flowable

@@ -46,15 +46,20 @@
@Override public void onSuccess(Object o) {
callMainSubscribeIfNecessary(d);
AutoDisposingObserverImpl.this.dispose();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be changed to AutoDisposableHelper.dispose(mainDisposable)

RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
assertThat(throwable instanceof ProtocolViolationException).isFalse();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't quite understand this test, as the ProtocolViolationException isn't obvious. Some sort of comment and asserting what you do expect should happen here

It also won't fail if this callback isn't hit, let's make it explicit somehow that we expect this callback to be hit

@ZacSweers
Copy link
Collaborator

Talked offline, closing in favor of #138

@ZacSweers ZacSweers closed this Nov 18, 2017
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.

4 participants