Skip to content

Conversation

@0xpablo
Copy link
Contributor

@0xpablo 0xpablo commented Nov 4, 2024

This caused continuations to be resumed more than once, crashing clients due to a violation of the Swift Concurrency contract.

I added tests that make it easy to reproduce the issue under the previous implementation

Screenshot 2024-11-04 at 09 38 15

This should fix #2563

This caused continuations to be resumed more than once, crashing clients due to a violation of the Swift Concurrency contract
try await withCheckedThrowingContinuation { continuation in
var didEmit = false
var didResume = false
let lock = RecursiveLock()
Copy link
Contributor

@nikolaykasyanov nikolaykasyanov Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take this with a grain of salt, as far as I can tell RecursiveLock is the to-go tool in this codebase.

  • does it have to be recursive?
  • can it be replaced with an atomic & compare-and-swap?
Copy link
Contributor Author

@0xpablo 0xpablo Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, that's a good point. I used RecursiveLock precisely because of that, I saw that was the tool being used to synchronize code in the rest of the codebase. I initially thought about that but given that even AtomicInt inside RxSwift is backed by a NSLock, I didn't want to introduce a different way to synchronize this.
If a maintainer wants me to switch to CAS for this I'm happy to do that.

Copy link

@hoc081098 hoc081098 Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think changing didResume to AtomicInt and using fetchOr might be better 🙏

Copy link
Contributor Author

@0xpablo 0xpablo Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, AtomicInt is backed by an NSLock so the only thing that would do is making this code less clear.

@0xpablo
Copy link
Contributor Author

0xpablo commented Aug 6, 2025

Hi @freak4pc, sorry to ping you, is there anything else I need to do to get this in a mergeable state? We would love to stop maintaining a fork of RxSwift, but this had become our top crash in Goodnotes.
Thanks!

@freak4pc
Copy link
Member

freak4pc commented Sep 9, 2025

Thanks for the code, sorry for the delay, I was on vacation. Will try to cut a release with this soon.

@freak4pc freak4pc merged commit 5004a18 into ReactiveX:main Sep 9, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants