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: Disposable returned from Single.subscribe() is not disposed after terminal event #5160

Closed
kxfeng opened this issue Mar 8, 2017 · 5 comments

Comments

@kxfeng
Copy link

kxfeng commented Mar 8, 2017

When using Single.subscribe(onSuccess, onError) , the returned Disposable is not disposed after terminal event. However , for Observable, Flowable, Maybe and Completable , the results are all disposed.

Here is the test code:

@Test
public void testDisposable() throws Exception {

	Disposable disposable;

	disposable = Single.just(1).subscribe(
		next -> System.out.println("Single Success"),
		error -> System.out.println("Single Error")
	);

	System.out.println("Single Disposed: " + disposable.isDisposed());

	disposable = Observable.just(1).subscribe(
		next -> System.out.println("Observable Next"),
		error -> System.out.println("Observable Error"),
		() -> System.out.println("Observable Complete")
	);

	System.out.println("Observable Disposed: " + disposable.isDisposed());
}

Output:

Single Success
Single Disposed: false

Observable Next
Observable Complete
Observable Disposed: true

I found the Disposeable not lazySet to DISPOSED in ConsumerSingleObserver compared with LambdaObserver. Is this a bug or there are some special reasons to do this?

ConsumerSingleObserver

@Override
public void onSuccess(T value) {
	try {
		onSuccess.accept(value);
	} catch (Throwable ex) {
		Exceptions.throwIfFatal(ex);
		RxJavaPlugins.onError(ex);
	}
}
LambdaObserver

@Override
public void onComplete() {
	if (!isDisposed()) {
		lazySet(DisposableHelper.DISPOSED);
		try {
			onComplete.run();
		} catch (Throwable e) {
			Exceptions.throwIfFatal(e);
			RxJavaPlugins.onError(e);
		}
	}
}

RxJava 2.0.6

@kxfeng kxfeng changed the title Disposable returned from Single.subscribe() is not disposed after terminal event 2.x: Disposable returned from Single.subscribe() is not disposed after terminal event Mar 8, 2017
@akarnokd akarnokd added this to the 2.0 backlog milestone Mar 8, 2017
@akarnokd
Copy link
Member

akarnokd commented Mar 8, 2017

Thanks for reporting. It looks like a simple oversight since the tests pass when I add the lazySets. See #5163.

@akarnokd
Copy link
Member

akarnokd commented Mar 8, 2017

Closing via #5163.

@apexkid
Copy link

apexkid commented Dec 1, 2018

Hello,

I am unable to understand the conclusion here. Is disposable supposed to be auto-disposed for Single? I wrote some code and i see it is not disposed. Is it the right behavior?

@akarnokd
Copy link
Member

akarnokd commented Dec 1, 2018

This issue has been closed and the fix has been available for a year now. What test did you write against which version?

@apexkid
Copy link

apexkid commented Dec 1, 2018

Sorry I have been testing it wrong. My bad!. Thanks for quick response though. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants