Closed anton-plebanovich closed 2 years ago
Hey @anton-plebanovich, thanks for reporting, I'll try your example in a bit.
Just wondering - what is the practical use case that you noticed this occur in?
Your example doesn't really allow tracking any issue, it's too much output. Please provide a more focused example and a practical use case where this is happening.
Notice that:
disposeBag
gets nilled out at the end of the scope. If you want to avoid this you need to move the disposeBag
to outside the scope.DispatchQueue.async
by hand, and using a scheduler. This can sometimes caused unexpected side-effects. I'd suggest staying in the scheduler realm. Waiting for a reproducible example and expected output :)
Thanks!
@freak4pc Crash there is to catch the issue since it's a race condition. You just need to set an exception breakpoint to be able to debug the crash state.
Here is an example of the same behavior without using DispatchQueue.async
- https://github.com/anton-plebanovich/SingleView/tree/c5805e9163aad5800a7fd827c7644b5a0385ff14
while true {
let disposeBag = DisposeBag()
let uuid = UUID().uuidString
let scheduler1 = SerialDispatchQueueScheduler(queue: DispatchQueue.global(qos: .default),
internalSerialQueueName: "RxSwift-Test-1-\(uuid)")
let scheduler2 = SerialDispatchQueueScheduler(queue: DispatchQueue.global(qos: .default),
internalSerialQueueName: "RxSwift-Test-2-\(uuid)")
Observable.just(1)
.observeOn(scheduler2)
.debug("scheduler2 - \(uuid)")
.do(onNext: { [weak disposeBag] _ in
if disposeBag == nil {
print("Operation executed after disposal - \(uuid)")
fatalError("Please put a breakpoint on that line or install an exception breakpoint")
}
})
.subscribeOn(scheduler2)
.observeOn(scheduler1)
.debug("scheduler1 - \(uuid)")
.subscribeOn(scheduler1)
.subscribe()
.disposed(by: disposeBag)
}
Closing this one since it is how concurrency and RxSwift are actually designed to work. If an operation is started, like .do(onNext:)
, it doesn't check if the chain was disposed and executes till the end. My bad.
Short description of the issue: Sometimes
next
event might be emitted after a sequence is disposed.Expected outcome: There shouldn't be events after the sequence is disposed.
What actually happens: Sometimes there are events after the sequence is disposed.
Self contained code example that reproduces the issue: Please clone, install pods and run https://github.com/anton-plebanovich/SingleView/tree/20110f6c1efefae3225cca57ef4e198357184d28
or just test this code:
Valid output will look like that:
Crash output will look like that:
RxSwift/RxCocoa/RxBlocking/RxTest version/commit RxSwift (5.1.1)
Platform/Environment
How easy is to reproduce? (chances of successful reproduce after running the self contained code)
Xcode version:
Installation method:
I have multiple versions of Xcode installed: (so we can know if this is a potential cause of your issue)
Level of RxSwift knowledge: (this is so we can understand your level of knowledge and formulate the response in an appropriate manner)