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

Map and flatMap operator chaining is not stack-safe #6322

Closed
pakoito opened this Issue Nov 21, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@pakoito

pakoito commented Nov 21, 2018

Expected behavior

Chaining large numbers of map and flatMap operators is stack-safe

Actual behavior

StackOverflow on ObservableMap.subscribeActual

Steps to reproduce

Range.create(0, 5000)
  .toList()
  .fold(Observable.just(0), { observable, x ->
    observable.map { x }
  }).block()
  .shouldBe(5000)

Yields a StackOverflow error:

    java.lang.StackOverflowError
        at java.lang.String.indexOf(String.java:1503)
        at java.lang.ClassLoader.checkName(ClassLoader.java:871)
        at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:1036)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:406)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at io.reactivex.Observable.subscribe(Observable.java:12088)
        at io.reactivex.internal.operators.observable.ObservableMap.subscribeActual(ObservableMap.java:33)
        at io.reactivex.Observable.subscribe(Observable.java:12084)
        at io.reactivex.internal.operators.observable.ObservableMap.subscribeActual(ObservableMap.java:33)
        at io.reactivex.Observable.subscribe(Observable.java:12084)
        at io.reactivex.internal.operators.observable.ObservableMap.subscribeActual(ObservableMap.java:33)
        at io.reactivex.Observable.subscribe(Observable.java:12084)
        ...

RxJava version

2.2.1

JVM version (e.g. java -version)

1.7 with Kotlin in the project, 1.8 in the system

@akarnokd

This comment has been minimized.

Member

akarnokd commented Nov 21, 2018

This is a known limitation and can't be resolved on our end. Method chaining is essentially eating up the stack. You have to restart the stack by introducing asynchrony for example or do a complete different flow.

@akarnokd akarnokd closed this Nov 21, 2018

@pakoito

This comment has been minimized.

pakoito commented Nov 22, 2018

Thanks for the fast reply :D

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