Skip to content

2.x: Unexpected Flowable.flatMap(...) behavior while handling an upstream error #6825

Closed
@ghost

Description

Hi,

I've discovered an unexpected behavior of the Flowable.flatMap() operator leading to a possible subscription leak. Localized my problem in the following scenario:

  1. RxJava version 2.2.16.
  2. Given a simple Rx chain of flowable1.flatMap(value -> flowable2).
  3. flowable1 emits a value (so that flatMap subscribes to flowable2).
  4. flowable1 emits an error.
    Expected result: flatMap disposes flowable2 upon handling the upstream error.
    Actual result: flowable2 remains subscribed after the entire Rx chain terminates because of the error.

Replacing the flatMap operator with concatMap fixes the problem (such a replacement is valid in my case). However I decided to raise this issue because such behavior of flatMap looks quite odd to me. Could somebody from RxJava team confirm whether my expectation is valid and the observed behavior is a defect?

I've reproduced this issue in a code snippet: https://gist.github.com/eugene-zolotko/b24cbc436bc0eab2ed5de539b9e4e312
I'm expecting this code to produce "flowable2 cancelled" output. But got "flowable2 error" instead, plus error2 gets thrown as UndeliverableException because it occurs after the entire chain is terminated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions