Skip to content
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

JVM crash/StackOverflow when merging observables using mergeWith #3035

Closed
mp911de opened this issue Jun 19, 2015 · 2 comments
Closed

JVM crash/StackOverflow when merging observables using mergeWith #3035

mp911de opened this issue Jun 19, 2015 · 2 comments

Comments

@mp911de
Copy link

mp911de commented Jun 19, 2015

JVM crashes when chaining a lot of Observables using mergeWith (tried to chain 1000 observables).

Crash report

siginfo:si_signo=SIGSEGV: si_errno=0, si_code=1 (SEGV_MAPERR), si_addr=0x0000000000000008

Stack: [0x00000001074c1000,0x00000001075c1000],  sp=0x00000001074d7b60,  free space=90k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.dylib+0x40ae31]
V  [libjvm.dylib+0x49e13a]
V  [libjvm.dylib+0x49e275]
v  ~RuntimeStub::StackOverflowError throw_exception
v  ~StubRoutines::call_stub
V  [libjvm.dylib+0x2c5186]
...
V  [libjvm.dylib+0x2bf655]
j  rx.internal.operators.OperatorMerge$InnerSubscriber.emit(Ljava/lang/Object;Z)V+145
j  rx.internal.operators.OperatorMerge$InnerSubscriber.onNext(Ljava/lang/Object;)V+3
j  rx.internal.operators.OperatorMerge$InnerSubscriber.emit(Ljava/lang/Object;Z)V+133
j  rx.internal.operators.OperatorMerge$InnerSubscriber.onNext(Ljava/lang/Object;)V+3
j  rx.internal.operators.OperatorMerge$InnerSubscriber.emit(Ljava/lang/Object;Z)V+133
...

See https://gist.github.com/mp911de/fd8cd7c35c67fddb0c81 for full crash report

Observed crash when running in debug mode. If running without debug, the JVM just hangs.
Java: 1.8.0_40
RxJava: 1.0.11

Code to reproduce:

Observable<String> observable = Observable.empty();
for (int i = 0; i < 1000; i++) {
    observable = observable.mergeWith(Observable.just("my string"));
}
observable.last().toBlocking().first();

Workaround:

List<Observable<String>> observables = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
    observables.add(Observable.just("my string"));
}
Observable.merge(observables).last().toBlocking().first();
@akarnokd
Copy link
Member

This is the drawback of long chains operators. You should use the workaround whenever possible or use
the merge(Observable<Observabe<T>>) overload with a PublishSubject if the number of inner Observables is not known upfront.

@mp911de
Copy link
Author

mp911de commented Jun 19, 2015

I was afraid of that. Thanks.

@mp911de mp911de closed this as completed Jun 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants