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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CoreData Thread Safety in retryCachedData #182

Conversation

sergiothinks2
Copy link
Contributor

@sergiothinks2 sergiothinks2 commented Feb 19, 2025

Problem

Some customers are experiencing crashes when the upload was not successful and the data was cached. The crash occurs on app relaunch when retryCachedData() is called, specifically when trying to access CoreData managed object properties on a different thread than the managed object context.

Changes

Modified retryCachedData() method to handle CoreData objects safely

  • Removed direct property access of CoreData managed objects across threads
  • Added conversion of managed objects to value types before processing
  • Maintained existing thread safety mechanisms (semaphore, queue handling)
  • Verified that test_fetchAllUploadData() is passing

Before

The original implementation accessed CoreData managed object properties (uploadData.type, uploadData.data, etc.) directly while iterating through them on a different thread than where they were fetched.

After

The new implementation:

  • Uses existing fetchAllUploadData() method which properly handles CoreData context
  • Immediately converts managed objects to value types using map
  • Processes these thread-safe value types in the upload loop

Copy link

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Files

Copy link

Warnings
⚠️ No CHANGELOG entry added.
⚠️ No tests added / modified.

Generated by 🚫 Danger Swift against bb829ab

@NachoEmbrace
Copy link
Contributor

Were you able to reproduce the crash?

@sergiothinks2 sergiothinks2 deleted the EMBR-6685-ios-sdk-causing-crash-at-app-startup-due-to-uploaddata-and-managedobjectcontext-on-different-threads branch February 25, 2025 17:01
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.

2 participants