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

ConcurrentDispatchQueueScheduler behavior #936

Closed
3 of 8 tasks
pgherveou opened this issue Oct 11, 2016 · 6 comments
Closed
3 of 8 tasks

ConcurrentDispatchQueueScheduler behavior #936

pgherveou opened this issue Oct 11, 2016 · 6 comments

Comments

@pgherveou
Copy link

pgherveou commented Oct 11, 2016

Short description of the issue:
On the latest beta, When using a Concurrent Dispatch Queue, the sequence emit a few times but never complete.

Self contained code example that reproduces the issue:

import Foundation
import PlaygroundSupport
import RxSwift

PlaygroundPage.current.needsIndefiniteExecution = true

let queue = DispatchQueue(
  label: "Test",
  attributes: .concurrent // commenting this to use a serial queue remove the issue
)

let scheduler: SchedulerType = ConcurrentDispatchQueueScheduler(queue: queue)

func makeSequence(label: String, period: RxTimeInterval) -> Observable<Int> {
  return Observable<Int>
    .interval(period, scheduler: scheduler)

    // note in this simplifed snippet, share is useless
    .shareReplay(1) // commenting this remove the issue,
}

let _ = makeSequence(label: "main", period: 1.0)
  .flatMapLatest { (index: Int) -> Observable<(Int, Int)> in
    return makeSequence(label: "nested", period: 0.2).map { (index, $0) }
  }
  .take(10)
  .mapWithIndex { ($1, $0.0, $0.1) }
  .subscribe(
    onNext: { print("\($0.0) emit (main: v\($0.1), nested: v\($0.2))") },
    onCompleted: { print("completed") }
)

Xcode version:

8.0

Expected outcome:

it should print

0 emit (main: v0, nested: v0)
1 emit (main: v0, nested: v1)
2 emit (main: v0, nested: v2)
3 emit (main: v0, nested: v3)
4 emit (main: v1, nested: v0)
5 emit (main: v1, nested: v1)
6 emit (main: v1, nested: v2)
7 emit (main: v1, nested: v3)
8 emit (main: v2, nested: v0)
9 emit (main: v2, nested: v1)
completed

What actually happens:
It prints

0 emit (main: v0, nested: v0)
1 emit (main: v0, nested: v1)
2 emit (main: v0, nested: v2)
3 emit (main: v0, nested: v3)

Installation method:

  • CocoaPods
  • Carthage
  • Git submodules

I have multiple versions of Xcode installed:
(so we can know if this is a potential cause of your issue)

  • yes (which ones)
  • no

Level of RxSwift knowledge:
(this is so we can understand your level of knowledge
and formulate the response in an appropriate manner)

  • just starting
  • I have a small code base
  • I have a significant code base
@kzaher
Copy link
Member

kzaher commented Oct 13, 2016

Hi @pgherveou ,

I'll investigate this. I have some ideas what could be happening.

kzaher added a commit that referenced this issue Oct 19, 2016
@kzaher
Copy link
Member

kzaher commented Oct 19, 2016

Hi @pgherveou,

I've pushed my attempt to repro this, but I was unable to. The code and unit tests look good too. It seems that maybe you have disposed dispose bag prematurely.

@kzaher
Copy link
Member

kzaher commented Oct 19, 2016

Anybody else can repro this?

@pgherveou
Copy link
Author

Sorry about the slow response.
I just ran the code in a playground again a few times
it works most of the time but I also got the same unexpected results a few time
Could it be an issue with Playground?

Here is the project I created
https://www.dropbox.com/sh/hjzkeffr5jplm04/AAA_PnciCTpR0zGopUg2VK4oa?dl=0

@kzaher
Copy link
Member

kzaher commented Oct 22, 2016

Hi @pgherveou ,

thnx for awesome repro steps. I've finally managed to repro it and fix it.

Pushed fix to master branch. Feel free to reopen the issue if you can still repo this.

@kzaher kzaher closed this as completed Oct 22, 2016
@pgherveou
Copy link
Author

Hi @kzaher just updated the sample project to 3.0 and it fixed the issue!
Thanks again for the great work.

Do you have any tips to debug this kind of issues, hopefully next time I can send you a PR instead of a simple sample project!

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