-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Merging streams from Future-based subscriptions fails for RxJava >= 0.17 #1022
Comments
It will call You can see the code here: https://github.com/Netflix/RxJava/blob/master/rxjava-core/src/main/java/rx/operators/OperatorMerge.java#L100 and the issue that resulted in this change at #897 Without this memory leaks can occur. If you look at the code you'll see that it only calls I think the problem is that your code is emitting a An
Thus, you should not emit anything to |
Thanks a lot for your extensive answer and for taking your time! I refactored my code to emit a String instead of the original Response object but observed still the very same behavior. I was also aware of the Rx Design Guidelines and the design principle not to emit values that rely on possibly cleaned resources (the Future in this case) and did not see any references to the original Future in the Response object. But you brought me on the right track by explaining the intended behavior of OperatorMerge and by looking at the stacktrace more carefully. The cause of the problem is a side-effect which became visible after the #897 optimizations. What happens is the following: Assuming you have two Streams 1 and 2 being merged together:
My workaround unfortunately is to ignore a concrete CancellationException in the callback (and abusing Exceptions for control flow :-( ):
|
Am I reading that correctly that the Future always will emit an exception even if already successfully completed? |
That is the behavior I am observing. Here is the set of String messages gathered by a ConcurrentLinkedQueue replaying the stream of merged events without the instanceof check and Stream 1 ending before Stream 2:
|
To be more precise: I observe this behavior if and only if one cancel()s (via unsubscribe()) a ning request Future that is already completed (as is done in Observable#merge()). If one unsubscribes to a Future that has not completed yet (i.e. by using Observable#take()) the CancellationException is not being emitted. This behavior really is dependent on the library you use (in my case ning). |
I'd suggest this is a bug with the Ning Future since it shouldn't do anything if cancel() is called if it has already received a successful response. |
Closing my issue as there is nothing to be done in RxJava. |
Hi,
The merge() operation fails for me starting from RxJava>=0.17. I refactored to the new OnSubscribe idiom as follows:
https://github.com/s-urbaniak/rxning/blob/master/src/main/java/org/urbaniak/ning/ResponseOnSubscribe.java
As you see I add create a Subscription from a future and add it the the subscriber.
I also provide a convenience factory method to create an Observable:
When I construct a merged Observable like so:
I recognize the following behavior and exception:
What happens (imho) is that CompositeSubscription.java:168 prematurely unsubsribes from any streams that are not completed yet.
I recognized this behavior in my code starting from #897
Am I missing something or is my assumption about the behavior of merge() fundamentally wrong or do I use the 0.17 facilities in a wrong way?
A minimal failing implementation is available at https://github.com/s-urbaniak/rxning for 0.17.x and a working version for 0.16.x at https://github.com/s-urbaniak/rxning/tree/0.16.1. A 'mvn test' will reveal the failing tests on the console.
Thanks for any pointers and thanks for this very great library!!!
Sergiusz
The text was updated successfully, but these errors were encountered: