-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
No initial emit under locks in share(replay: 1, scope: .whileConnected)
#2654
base: main
Are you sure you want to change the base?
No initial emit under locks in share(replay: 1, scope: .whileConnected)
#2654
Conversation
… do that under their own lock
share(replay: 1)
and Subjects
share(replay: 1)
and Subjects
share(replay: 1)
and Subject
s
share(replay: 1)
and Subject
sshare(replay: 1)
and Subject
s
I'll review this later, but wanted to say I highly appreciate your PR, and the apology 🙌 |
Could you add a unit tests that validates the fix against the issue you found? |
0f88e19
to
853faae
Compare
share(replay: 1)
and Subject
sshare(replay: , scope: .whileConnected)
share(replay: , scope: .whileConnected)
share(replay: any, scope: .whileConnected)
share(replay: any, scope: .whileConnected)
share(replay: 1, scope: .whileConnected)
I have prepared tests to test the specific issue, although, now that I think of it, they could be implemented better:
But the main take away I guess is that it checks for the original issue, despite it intrinsically being impossible to happen. |
UPDATE2: unit tests have uncovered another unrelated issue #2655 . This PR provides fix for that too.
UPDATE: turns out, Subjects are not broken, the issue is 100% centralized in the
ShareReplay1WhileConnected
This pull request aims to fix #2653.
The original issue stems from the fact that:
ShareWhileConnected
,ShareReplay1WhileConnected
ReplaySubject, BehaviorSubject and PublishSubjectemit their initial events upon subscription while holding onto their internal locks that protect their mutable stateThe last 3 points perfectly describe the behavior of a
zip
operator, which:ShareReplay1WhileConnect
or anySubject
, with these sources retaining their locksIn a multithreaded environment, these conditions can race, and this can produce a deadlock. This PR positions "emission upon subscription under lock" as the core issue and tries to fix specifically this behavior.
Special considerations:
Additionally:
@freak4pc I would like to say sorry for this comment. I really wasn't planning to add anything valuable to the conversation, and my behavior was really counter productive here. This wasn't a troll comment, it was just - I was amused by the fact that RxSwift can break, I found it funny.
@danielt1263 Also I would like to say thank you for your time and the fact that you responded to me.
I would also like to say sorry to you both for this comment - the vagueness of my answer actually permitted an interpretation where I am not only posting nothing of value, but also deliberately try and insult you or the framework. This wasn't my intention, and I'm sorry that I came off this way.
Fixes #2655
Fixes #2653