RxJava icon indicating copy to clipboard operation
RxJava copied to clipboard

2.x: Flowable.blockingSubscribe(lambdas) is unbounded and can lead to OOME

Open akarnokd opened this issue 8 years ago • 2 comments

I can't remember why, but Flowable.blockingSubscribe(Consumer,...) uses unbounded requests, which can lead to OutOfMemoryError in both synchronous and asynchronous scenarios.

The problem was raised in this StackOverflow question and apart from the obvious solutions, having such unbounded operator over an asynchronous boundary can be a problem regardless.

Possible resolutions:

  • Behavior change: bound it to bufferSize() in 2.x
  • (and/or) Introduce overload(s) with prefetch but leave the existing ones unbounded

Alternatively, this could be deferred until 3.x without worrying of the behavior change.

akarnokd avatar Apr 30 '18 21:04 akarnokd

Flowable.blockingSubscribe(Consumer,…) is using Functions.MaxRequestSubscription() which could lead to OutOfMemoryError. Is it the issue? In that case, I suggest to:

  • Keep existing Flowable.blockingSubscribe(Consumer,…) unbounded
  • Deprecate existing Flowable.blockingSubscribe(Consumer,…)
  • Introduce new overloads with bufferSize() and prefetch

WDYT? Can I work on this?

RomanWuattier avatar May 20 '18 21:05 RomanWuattier

Create a new overload:

blockingSubscribe(Consumer<? super T> onNext, Consumer<? super Throwable> onError, Action onComplete, int bufferSize)

have a dedicated implementation servicing it and leave the other overloads unbounded.

akarnokd avatar May 20 '18 21:05 akarnokd