-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Don’t attempt to remove elements of empty queues. #2009
Conversation
This seems like a good idea no matter what, but I'm struggling to understand the chain of events that could lead us here. It seems like we only try to dequeue a signal producer if one has just completed or interrupted, so shouldn't there be a one-to-one correspondence there? 😕 |
Yeah, it’s unclear how this is happening—perhaps threading hijinks in my exploration of the deadlocks? I was misinterpreting this use of the method as intending it to be empty sometimes, rather than intending it to be emptied by the call—mea culpa. |
From what I experienced, the following code prevents the crash (but I didn't understand why): func startNextSignalProducer(signalProducer: SignalProducer<T, E>) {
signalProducer.startWithSignal { signal, disposable in
self.disposable.addDisposable(disposable)
let d = signal.observe(Signal.Observer { event in
switch event {
case .Completed, .Interrupted:
if let nextSignalProducer = self.dequeueSignalProducer() {
self.startNextSignalProducer(nextSignalProducer)
}
default:
self.observer.put(event)
}
})
self.disposable.addDisposable(d)
}
} |
Well, this certainly can't hurt, so I'll merge it. |
Don’t attempt to remove elements of empty queues.
@@ -1159,7 +1159,7 @@ private final class ConcatState<T, E: ErrorType> { | |||
// Active producers remain in the queue until completed. Since | |||
// dequeueing happens at completion of the active producer, the | |||
// first producer in the queue can be removed. | |||
queue.removeAtIndex(0) | |||
if !queue.isEmpty { queue.removeAtIndex(0) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just saw a bad access on this line (post-PR). Not sure how that's possible. 😕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that means either concurrency bug or Swift bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not both???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
He said or
not xor
😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With Swift, both is practically guaranteed.
Outer signal observer should be notified of Completed event after all inner producers have completed. It should fix #2009 (comment)
Fixes a crasher.