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

[Bug]The Publishers.ReceiveOn may lead to subscriber never receive the published signal when scheduler is concurrent queue. #234

Open
dito010 opened this issue Jun 2, 2022 · 0 comments

Comments

@dito010
Copy link

dito010 commented Jun 2, 2022

For Future type publisher, it send signal then send completion to the Publishers.ReceiveOn.

In Publishers.ReceiveOn:

for signal:

scheduler.schedule(options: options) {
   self.scheduledReceive(input)
}

for completion:

scheduler.schedule(options: options) {
   self.scheduledReceive(completion: completion)
}

but the scheduler may execute the completion command before signal, in this case, the state.subscription is nil then returned.

private func scheduledReceive(_ input: Input) {
  lock.lock()
  guard state.subscription != nil else {
    lock.unlock()
    return
  }
   
   // ...
}

This result is not match expectations.

And the Apple's Combine has the same bug yet 😂.

We should promise the subscriber will always receive the signal?

Some solution code:

// for signal.
lockedActions.write().safeRun({
    $0.pointee.insert({ [weak self] in self?.scheduledReceive(input) }, at: 0)
})
scheduler.schedule(options: options) {
    self.lockedActions.write().safeRun({ $0.pointee.popLast()?() })
}

// for complection.
lockedActions.write().safeRun({
    $0.pointee.insert({ [weak self] in self?.scheduledReceive(completion: completion) }, at: 0)
})
scheduler.schedule(options: options) {
    self.lockedActions.write().safeRun({ $0.pointee.popLast()?() })
}
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

1 participant