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

Ensure thread safe access to UIViewController associated properties #153

Merged
merged 2 commits into from
Dec 24, 2024

Conversation

ArielDemarco
Copy link
Collaborator

@ArielDemarco ArielDemarco commented Dec 18, 2024

Overview

This PR addresses a potential crash caused by threading issues when accessing or modifying UIViewController properties using Objective-C runtime associations (objc_setAssociatedObject and objc_getAssociatedObject) on a background thread.

An example: when a UIViewController with a very short lifespan (like we observe on, for example SwiftUI.UIKitNavigationController) is being deallocated, we could be adding associated objects at the same time, leading to unsafe interactions with the Objective-C runtime.

To prevent this, the code has been updated to ensure all accesses to vc.emb_identifier (a property backed by objc_setAssociatedObject) are performed on the main thread, ensuring the UIViewController is in the rendering process and not being deallocated.

Extra

Found out that LengthOfNameValidator was preventing to push some .viewLoad/.view spans due to name length. We've added a whitelist to prevent this from happening.

@ArielDemarco ArielDemarco requested a review from a team as a code owner December 18, 2024 21:19
Copy link

github-actions bot commented Dec 18, 2024

Dependency Review

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

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Files

Copy link

github-actions bot commented Dec 18, 2024

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

Generated by 🚫 Danger Swift against b40b729

Copy link

codecov bot commented Dec 18, 2024

Codecov Report

Attention: Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.

Project coverage is 90.57%. Comparing base (69ed424) to head (b40b729).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...Core/Capture/UX/View/UIViewControllerHandler.swift 93.75% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #153      +/-   ##
==========================================
- Coverage   90.61%   90.57%   -0.05%     
==========================================
  Files         419      419              
  Lines       28090    28105      +15     
==========================================
+ Hits        25455    25456       +1     
- Misses       2635     2649      +14     
Files with missing lines Coverage Δ
.../Validation/Validators/LengthOfNameValidator.swift 100.00% <100.00%> (ø)
...Core/Capture/UX/View/UIViewControllerHandler.swift 96.83% <93.75%> (+0.03%) ⬆️

... and 3 files with indirect coverage changes

@ArielDemarco ArielDemarco merged commit 720965d into main Dec 24, 2024
10 checks passed
@ArielDemarco ArielDemarco deleted the fix-crash-associated-object-in-deinit branch December 24, 2024 15:37
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