Skip to content

Data Race Condition in saveInSmartStore - User Updates Lost During Slow Network Sync #3974

@nzsrini

Description

@nzsrini

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:

  1. Sync starts with in-memory records from time T0
  2. User modifies data at time T1 (while sync is ongoing due to slow network)
  3. Sync completes at time T2, saving the stale T0 data and overwriting T1 changes

Reproduction Scenario

  1. Start a sync operation with slow network connectivity
  2. While sync is in progress, user updates local records through the app UI
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions