Skip to content

fix error handling in onBackpressureBuffer #3639

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
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 @@ -22,6 +22,7 @@
import rx.Observable.Operator;
import rx.Producer;
import rx.Subscriber;
import rx.exceptions.Exceptions;
import rx.exceptions.MissingBackpressureException;
import rx.functions.Action0;
import rx.internal.util.BackpressureDrainManager;
Expand Down Expand Up @@ -156,7 +157,15 @@ private boolean assertCapacity() {
"Overflowed buffer of "
+ baseCapacity));
if (onOverflow != null) {
onOverflow.call();
try {
onOverflow.call();
} catch (Throwable e) {
Exceptions.throwIfFatal(e);
Copy link
Member

Choose a reason for hiding this comment

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

Need to notify the plugin instead of swallowing the non fatal exceptions.

Copy link
Member

Choose a reason for hiding this comment

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

It does not swallow it but emits via L164 to the child subscriber.

Copy link
Member

Choose a reason for hiding this comment

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

yeah. Didn't notice that

manager.terminateAndDrain(e);
// this line not strictly necessary but nice for clarity
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

// and in case of future changes to code after this catch block
return false;
}
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@
*/
package rx.internal.operators;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;

import rx.Observable;
import rx.Observable.OnSubscribe;
Expand All @@ -27,12 +34,10 @@
import rx.Subscription;
import rx.exceptions.MissingBackpressureException;
import rx.functions.Action0;
import rx.functions.Action1;
import rx.observers.TestSubscriber;
import rx.schedulers.Schedulers;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class OperatorOnBackpressureBufferTest {

@Test
Expand Down Expand Up @@ -147,5 +152,30 @@ public void call(Subscriber<? super Long> s) {
}

});

private static final Action0 THROWS_NON_FATAL = new Action0() {

@Override
public void call() {
throw new RuntimeException();
}};

@Test
public void testNonFatalExceptionThrownByOnOverflowIsNotReportedByUpstream() {
final AtomicBoolean errorOccurred = new AtomicBoolean(false);
TestSubscriber<Long> ts = TestSubscriber.create(0);
infinite
.subscribeOn(Schedulers.computation())
.doOnError(new Action1<Throwable>() {
@Override
public void call(Throwable t) {
errorOccurred.set(true);
}
})
.onBackpressureBuffer(1, THROWS_NON_FATAL)
.subscribe(ts);
ts.awaitTerminalEvent();
assertFalse(errorOccurred.get());
}

}