Fix thread-safety race in SFUserAccount encodeWithCoder#4042
Merged
brandonpage merged 1 commit intoMay 29, 2026
Merged
Conversation
encodeWithCoder accessed ivars directly without synchronizing on the concurrent queue, while setters (setAccessScopes, setIdData, setCustomDataObject:forKey:) use dispatch_barrier_async. This caused a race where encoding immediately after setting these properties could capture stale (nil/empty) values. Wrap the encoder calls in dispatch_sync on _syncQueue so pending barrier writes complete before the ivars are read. Fixes testUserAccountEncoding failures on iOS 26 nightly CI.
Clang Static Analysis Issues
Generated by 🚫 Danger |
|
||||||||||||||||
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #4042 +/- ##
==========================================
- Coverage 70.67% 68.15% -2.53%
==========================================
Files 245 245
Lines 21462 21464 +2
==========================================
- Hits 15169 14629 -540
- Misses 6293 6835 +542
🚀 New features to boost your workflow:
|
|
||||||||||||||||||
|
||||||||||||||
wmathurin
approved these changes
May 22, 2026
bbirman
approved these changes
May 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
encodeWithCoder:accessed ivars (_accessScopes,_idData,_customData) directly without synchronizing on the concurrent queue, while their setters usedispatch_barrier_async. This caused a race where encoding immediately after setting these properties could capture stale (nil/empty) values.dispatch_syncon_syncQueueso pending barrier writes complete before the ivars are read.Test plan
testUserAccountEncodingpasses on iOS 26 (Xcode 26) nightly CISFUserAccountfrom different threads