Skip to content

Fix Thread Safety for Unsubscribe of Window #1833

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
Nov 8, 2014
Merged
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 @@ -61,7 +61,8 @@ final class ExactSubscriber extends Subscriber<T> {
final Subscriber<? super Observable<T>> child;
int count;
BufferUntilSubscriber<T> window;
Subscription parentSubscription = this;
volatile boolean noWindow = true;
final Subscription parentSubscription = this;
public ExactSubscriber(Subscriber<? super Observable<T>> child) {
/**
* See https://github.com/ReactiveX/RxJava/issues/1546
Expand All @@ -77,7 +78,7 @@ public ExactSubscriber(Subscriber<? super Observable<T>> child) {
@Override
public void call() {
// if no window we unsubscribe up otherwise wait until window ends
if(window == null) {
if(noWindow) {
parentSubscription.unsubscribe();
}
}
Expand All @@ -94,13 +95,15 @@ public void onStart() {
@Override
public void onNext(T t) {
if (window == null) {
noWindow = false;
window = BufferUntilSubscriber.create();
child.onNext(window);
}
window.onNext(t);
if (++count % size == 0) {
window.onCompleted();
window = null;
noWindow = true;
if (child.isUnsubscribed()) {
parentSubscription.unsubscribe();
return;
Expand Down Expand Up @@ -130,7 +133,7 @@ final class InexactSubscriber extends Subscriber<T> {
final Subscriber<? super Observable<T>> child;
int count;
final List<CountedSubject<T>> chunks = new LinkedList<CountedSubject<T>>();
Subscription parentSubscription = this;
final Subscription parentSubscription = this;

public InexactSubscriber(Subscriber<? super Observable<T>> child) {
/**
Expand Down