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

[2.2.6] window() operator leaks subscriptions #6397

Closed
vganin opened this issue Feb 5, 2019 · 2 comments · Fixed by #6398
Closed

[2.2.6] window() operator leaks subscriptions #6397

vganin opened this issue Feb 5, 2019 · 2 comments · Fixed by #6398

Comments

@vganin
Copy link

vganin commented Feb 5, 2019

Hi,

I believe I encountered window operator leaking observable subscriptions. Here is a small test to reproduce the issue:

fun main(args: Array<String>) {
    observable(1).window(observable(2).filter { it == 1 }, Function { _: Int -> observable(3).filter { it == 1 } }, 1)
            .subscribe()
            .dispose()
}

private fun observable(n: Int): Observable<Int> {
    return Observable.create<Int> { emitter ->
        println("Subscribed! $n")
        emitter.onNext(1)
        emitter.onNext(2)
        emitter.onNext(3)
        emitter.setCancellable { println("Cancelled! $n") }
    }
}

The output is:

Subscribed! 2
Subscribed! 3
Cancelled! 3
Subscribed! 1

From the output you can see that cancellables for observable(1) and observable(2) are never called.

This may be severe if cancellables are used to dispose some (possibly) critical resources upon subscription disposal.

@vganin vganin changed the title [2.2.6] window operator leaks subscriptions [2.2.6] window() operator leaks subscriptions Feb 5, 2019
@akarnokd
Copy link
Member

akarnokd commented Feb 5, 2019

The operator will not dispose the inner windows if you dispose the outer sequence of windows. You should not ignore the inner windows produced by the operator. Most use cases have flatMap to merge the windows back which will dispose all of them as you expected.

@akarnokd
Copy link
Member

akarnokd commented Feb 5, 2019

The printout is certainly odd. I'll investigate further.

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

Successfully merging a pull request may close this issue.

2 participants