-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Open
Description
I have been writing unit tests for #2654 and found a bug in ConnectableObservableAdapter:
- Multicast operator produces a
ConnectableObservableAdapter - when you subscribe to it via
Observableinterface, it evaluateslazySubjectcomputed property to instantiate aSubjectwithout synchronization - this can cause the
makeSubjectto be called more than once if you perform several calls tosubscribeconcurrently - and if it's going to return different instances of
Subject, this means that some of the concurrent subscriptions will actually be looking at the wrong instance ofSubject, which will be overwritten during the data race.
This setup will naturally occur if:
- you are doing
flatMapinto aconnectableobservable concurrently - if you use
refCountoperator, subscribing concurrently share(replay: 2+, scope: .whileConnected)because it's implemented viamulticast+refCount
You can see the code that reproduces this issue here: https://github.com/isaac-weisberg/RxSwiftDeadlock/tree/connect-unsafe
I am going to provide a fix for this issue inside #2654 since it's required to make all the tests run successfully.
Metadata
Metadata
Assignees
Labels
No labels