Skip to content

3.x: Fix refCount not resetting when termination triggers cross-cancel #6609

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

Merged
merged 1 commit into from
Aug 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,15 @@ void cancel(RefConnection rc) {

void terminated(RefConnection rc) {
synchronized (this) {
if (connection != null && connection == rc) {
connection = null;
if (connection == rc) {
if (rc.timer != null) {
rc.timer.dispose();
rc.timer = null;
}
if (--rc.subscriberCount == 0) {
connection = null;
source.reset();
}
}
if (--rc.subscriberCount == 0) {
source.reset();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,15 @@ void cancel(RefConnection rc) {

void terminated(RefConnection rc) {
synchronized (this) {
if (connection != null && connection == rc) {
connection = null;
if (connection == rc) {
if (rc.timer != null) {
rc.timer.dispose();
rc.timer = null;
}
if (--rc.subscriberCount == 0) {
connection = null;
source.reset();
}
}
if (--rc.subscriberCount == 0) {
source.reset();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package io.reactivex.internal.operators.flowable;

import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

import java.io.IOException;
Expand Down Expand Up @@ -1454,4 +1455,22 @@ public void publishRefCountShallBeThreadSafe() {
.assertComplete();
}
}
}

@Test
public void upstreamTerminationTriggersAnotherCancel() throws Exception {
ReplayProcessor<Integer> rp = ReplayProcessor.create();
rp.onNext(1);
rp.onComplete();

Flowable<Integer> shared = rp.share();

shared
.buffer(shared.debounce(5, TimeUnit.SECONDS))
.test()
.assertValueCount(2);

shared
.buffer(shared.debounce(5, TimeUnit.SECONDS))
.test()
.assertValueCount(2);
}}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package io.reactivex.internal.operators.observable;

import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

import java.io.IOException;
Expand All @@ -22,7 +23,7 @@
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;

import org.junit.Test;
import org.junit.*;
import org.mockito.InOrder;

import io.reactivex.*;
Expand Down Expand Up @@ -1267,8 +1268,6 @@ public void cancelTerminateStateExclusion() {
.publish()
.refCount();

o.cancel(null);

o.cancel(new RefConnection(o));

RefConnection rc = new RefConnection(o);
Expand Down Expand Up @@ -1412,4 +1411,23 @@ public void publishRefCountShallBeThreadSafe() {
.assertComplete();
}
}

@Test
public void upstreamTerminationTriggersAnotherCancel() throws Exception {
ReplaySubject<Integer> rs = ReplaySubject.create();
rs.onNext(1);
rs.onComplete();

Observable<Integer> shared = rs.share();

shared
.buffer(shared.debounce(5, TimeUnit.SECONDS))
.test()
.assertValueCount(2);

shared
.buffer(shared.debounce(5, TimeUnit.SECONDS))
.test()
.assertValueCount(2);
}
}