-
Notifications
You must be signed in to change notification settings - Fork 427
Description
Issue: Data Race Condition in saveInSmartStore - User Updates Lost During Slow Network Sync
Problem Description
The saveInSmartStore method in SFSyncTarget.m uses in-memory record objects that can become stale during long-running sync operations. When network speeds are slow and sync operations take extended time to complete, users may update local data while the sync is still in progress. This creates a race condition where the sync operation overwrites the user's recent changes with stale data from memory.
Root Cause
The saveInSmartStore method operates on NSArray *records passed as parameters, which are snapshots of data at the time the sync operation began. During the sync process:
- Sync starts with in-memory records from time T0
- User modifies data at time T1 (while sync is ongoing due to slow network)
- Sync completes at time T2, saving the stale T0 data and overwriting T1 changes
Reproduction Scenario
- Start a sync operation with slow network connectivity
- While sync is in progress, user updates local records through the app UI
- Sync operation completes and calls saveInSmartStore with original in-memory data
User's recent local changes are lost/overwritten
Expected Behavior
• User's local changes should be preserved and not overwritten by sync operations
• Sync operations should either merge changes intelligently or detect conflicts
• Local modifications should take precedence over stale in-memory sync data
Impact
• Severity: High - Data loss issue
• User Experience: Poor - Users lose their work unexpectedly
• Frequency: More common with slow network connections