Skip to content

Fix thread-safety race in SFUserAccount encodeWithCoder#4042

Merged
brandonpage merged 1 commit into
forcedotcom:devfrom
brandonpage:fix/encode-with-coder-thread-safety
May 29, 2026
Merged

Fix thread-safety race in SFUserAccount encodeWithCoder#4042
brandonpage merged 1 commit into
forcedotcom:devfrom
brandonpage:fix/encode-with-coder-thread-safety

Conversation

@brandonpage
Copy link
Copy Markdown
Contributor

Summary

  • encodeWithCoder: accessed ivars (_accessScopes, _idData, _customData) directly without synchronizing on the concurrent queue, while their setters use dispatch_barrier_async. This caused a race where encoding immediately after setting these properties could capture stale (nil/empty) values.
  • Wraps the encoder calls in dispatch_sync on _syncQueue so pending barrier writes complete before the ivars are read.

Test plan

  • Verify testUserAccountEncoding passes on iOS 26 (Xcode 26) nightly CI
  • Verify no deadlocks when archiving SFUserAccount from different threads
  • Run full SalesforceSDKCore test suite

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.
@github-actions
Copy link
Copy Markdown

1 Warning
⚠️ Static Analysis found an issue with one or more files you modified. Please fix the issue(s).

Clang Static Analysis Issues

File Type Category Description Line Col
SFUserAccount Nullability Memory error nil assigned to a pointer which is expected to have non-null value 263 22
SFUserAccount Nullability Memory error nil passed to a callee that requires a non-null 1st parameter 447 18
SFUserAccount Nullability Memory error nil passed to a callee that requires a non-null 1st parameter 449 18

Generated by 🚫 Danger

Copy link
Copy Markdown
Contributor

@sfdctaka sfdctaka left a comment

Choose a reason for hiding this comment

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

LGTM!

@github-actions
Copy link
Copy Markdown

TestsPassed ☑️SkippedFailed ❌️
SalesforceSDKCore iOS ^18 Test Results632 ran631 ✅1 ❌
TestResult
SalesforceSDKCore iOS ^18 Test Results
SFSDKAuthConfigUtilTests.testBrowserBasedLoginEnabled❌ failure

@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.15%. Comparing base (a2d6db8) to head (d4c9ce3).

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     
Components Coverage Δ
Analytics 70.78% <ø> (ø)
Common 70.69% <ø> (-0.19%) ⬇️
Core 61.59% <100.00%> (-3.90%) ⬇️
SmartStore 73.44% <ø> (ø)
MobileSync 88.79% <ø> (ø)
Files with missing lines Coverage Δ
...esforceSDKCore/Classes/UserAccount/SFUserAccount.m 80.62% <100.00%> (+0.15%) ⬆️

... and 28 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Copy Markdown

TestsPassed ☑️SkippedFailed ❌️
SalesforceSDKCore iOS ^26 Test Results632 ran630 ✅2 ❌
TestResult
SalesforceSDKCore iOS ^26 Test Results
SFSDKAuthConfigUtilTests.testBrowserBasedLoginEnabled❌ failure
SalesforceRestAPITests.testUploadOwnedFilesDelete❌ failure

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 22, 2026

TestsPassed ✅SkippedFailed
AuthFlowTester UI Test Results all1 ran1 ✅
TestResult
No test annotations available

@brandonpage brandonpage merged commit bac0171 into forcedotcom:dev May 29, 2026
25 of 30 checks passed
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.

4 participants