Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed forced optional type used in Atomic #254

Merged
merged 4 commits into from May 8, 2020

Conversation

VojtaStavik
Copy link
Contributor

@VojtaStavik VojtaStavik commented May 8, 2020

In the PR:

  • value in Atomic is no longer treated as Optional by default
  • Atomic stress tests random crash (hopefully) fixed 馃

@buh @b-onc Please review and test this extremely carefully. I touched a lot of different parts of the app and could easily introduce some copy-paste/typo kind of bug 馃檹

@VojtaStavik VojtaStavik requested review from buh and b-onc May 8, 2020 08:50
Copy link
Contributor

@b-onc b-onc left a comment

Choose a reason for hiding this comment

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

LGTM, Atomic is most probably not used by end users so I'm not sure to put this under "Breaking Changes", I'd say we put it under "Changed" so we can release it in 2.2

CHANGELOG.md Outdated
Comment on lines 9 to 11
### 鈿狅笍 Breaking Changes
- `Atomic.get()` no longer returns an optional type if the wrapped type itself is not optional. `Atomic.init(_:)` now always requires the initial value [#241](https://github.com/GetStream/stream-chat-swift/issues/241).

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should merge this into release/3.0 since it's breaking and touches a lot of different parts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to merge it to master. Let me redo it in a bit more compatible way.

Copy link
Contributor

@buh buh left a comment

Choose a reason for hiding this comment

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

Looks great!
Finally non-optional!
Only the same question about CHANGELOG.

@VojtaStavik VojtaStavik force-pushed the remove-atomic-optional branch 2 times, most recently from 2cb72f3 to 3597392 Compare May 8, 2020 11:13
DispatchQueue.random.async {
// We need to capture the value explicitly. Without this the tests randomly crashes after
// `atomicValue` is assigned to `nil`.
DispatchQueue.random.async { [atomicValue] in
Copy link
Contributor Author

Choose a reason for hiding this comment

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

10 minutes to identify the problem + 50 minutes figuring out how to fix it = [atomicValue]

@VojtaStavik
Copy link
Contributor Author

@buh @b-onc I changed to PR to be much less destructive. I feel much better with merging this to master now.

@VojtaStavik VojtaStavik requested a review from b-onc May 8, 2020 11:16
Copy link
Contributor

@b-onc b-onc left a comment

Choose a reason for hiding this comment

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

I'd appreciate a write-up stating why explicit capture solved the crash!
馃殺

Comment on lines +13 to +14
/// - Note: Even though the value guarded by `Atomic` is thread-safe, the `Atomic` class itself is not. Mutating the instance
/// itself from multiple threads can cause a crash.
Copy link
Contributor

Choose a reason for hiding this comment

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

馃憤

@VojtaStavik
Copy link
Contributor Author

@b-onc As far as I understand it, capturing it explicitly creates a strong reference to atomicValue and keeps it alive until all reads are safely finished. Without [atomicValue] it doesn't create the reference and thus the object can get deinited while the read block is accessing it.

@VojtaStavik VojtaStavik merged commit a86bbff into master May 8, 2020
@delete-merged-branch delete-merged-branch bot deleted the remove-atomic-optional branch May 8, 2020 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants