Skip to content

Conversation

noahsmartin
Copy link
Contributor

@noahsmartin noahsmartin commented Aug 12, 2025

SentryApplication was doing 2 things. It was wrapping UI/NSApplication methods for unit testing purposes, and it was attempting to provide background thread safe access to isActive. I say attempting because it used Notification Center to listen for foreground/background and change a state var, but didn't have any kind of locking. So it was prone to a data race where the main thread would write to it through the notification at the same time a background thread read from it.

The other issue was the AppKit version direct called in to NSApplication and made no attempt at being thread safe, so this object had different amounts of safety depending on the platform.

This PR separates these two behaviors, so SentryApplication is just the system API wrapping (with some extra post-processing on system APIs) and ThreadsafeApplication is a UIKit only thread safe API. This ThreadsafeApplication now uses locks to ensure there isn't a data race. Luckily our code was not relying on the macOS version being thread safe, and now that is just more clear at compile time.

#skip-changelog

@noahsmartin noahsmartin force-pushed the updateApplication branch 2 times, most recently from 721aa8c to fa65d1b Compare August 12, 2025 23:04
Copy link

codecov bot commented Aug 12, 2025

Codecov Report

❌ Patch coverage is 41.11111% with 106 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.653%. Comparing base (3ffd0e5) to head (c2e34f8).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
Sources/Swift/Helper/SentryApplication+UIKit.swift 20.769% 103 Missing ⚠️
Sources/Swift/Helper/ThreadSafeApplication.swift 90.625% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #5900       +/-   ##
=============================================
- Coverage   86.752%   86.653%   -0.099%     
=============================================
  Files          428       429        +1     
  Lines        36882     36857       -25     
  Branches     17412     17396       -16     
=============================================
- Hits         31996     31938       -58     
- Misses        4839      4873       +34     
+ Partials        47        46        -1     
Files with missing lines Coverage Δ
Sources/Sentry/SentryANRTrackingIntegration.m 98.809% <100.000%> (-0.596%) ⬇️
Sources/Sentry/SentryClient.m 98.944% <100.000%> (ø)
Sources/Sentry/SentryCrashIntegration.m 99.200% <ø> (ø)
Sources/Sentry/SentryCrashWrapper.m 91.200% <100.000%> (+0.070%) ⬆️
Sources/Sentry/SentryDependencyContainer.m 88.584% <100.000%> (+0.052%) ⬆️
...rces/Sentry/SentryDependencyContainerSwiftHelper.m 100.000% <100.000%> (ø)
Sources/Sentry/SentrySDKInternal.m 86.885% <ø> (ø)
Sources/Sentry/SentrySessionReplayIntegration.m 87.108% <100.000%> (+0.047%) ⬆️
Sources/Sentry/SentrySessionTracker.m 99.137% <100.000%> (ø)
Sources/Sentry/SentryTracer.m 97.049% <ø> (-1.148%) ⬇️
... and 4 more

... and 4 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3ffd0e5...c2e34f8. Read the comment docs.

@noahsmartin noahsmartin force-pushed the updateApplication branch 3 times, most recently from a115144 to 00a642f Compare August 13, 2025 03:18
Copy link
Contributor

github-actions bot commented Aug 13, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1223.92 ms 1248.04 ms 24.13 ms
Size 23.75 KiB 953.91 KiB 930.16 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
2609f7a 1218.17 ms 1241.34 ms 23.17 ms
ad964ca 1234.73 ms 1254.88 ms 20.15 ms
c6c1cb7 1235.71 ms 1263.80 ms 28.08 ms
5258fb8 1207.92 ms 1234.51 ms 26.59 ms
efab7d3 1219.98 ms 1252.12 ms 32.14 ms
83bb978 1238.33 ms 1260.04 ms 21.71 ms
0ee162c 1226.90 ms 1261.72 ms 34.83 ms
c6d2354 1226.53 ms 1252.69 ms 26.16 ms
2de3f92 1207.56 ms 1234.96 ms 27.40 ms
f8029e2 1245.16 ms 1261.32 ms 16.16 ms

App size

Revision Plain With Sentry Diff
2609f7a 23.75 KiB 867.04 KiB 843.29 KiB
ad964ca 23.75 KiB 913.17 KiB 889.42 KiB
c6c1cb7 23.75 KiB 928.15 KiB 904.40 KiB
5258fb8 23.75 KiB 874.45 KiB 850.70 KiB
efab7d3 23.75 KiB 912.78 KiB 889.03 KiB
83bb978 23.75 KiB 920.64 KiB 896.89 KiB
0ee162c 23.75 KiB 933.33 KiB 909.58 KiB
c6d2354 23.75 KiB 919.70 KiB 895.95 KiB
2de3f92 23.75 KiB 919.69 KiB 895.94 KiB
f8029e2 23.75 KiB 893.72 KiB 869.97 KiB

Previous results on branch: updateApplication

Startup times

Revision Plain With Sentry Diff
e2a0e66 1198.58 ms 1231.93 ms 33.35 ms
8ce26a2 1225.54 ms 1242.65 ms 17.10 ms
ee17551 1217.88 ms 1245.02 ms 27.14 ms
621c433 1219.33 ms 1246.92 ms 27.59 ms
289850d 1216.71 ms 1239.00 ms 22.29 ms

App size

Revision Plain With Sentry Diff
e2a0e66 23.75 KiB 928.30 KiB 904.55 KiB
8ce26a2 23.75 KiB 928.00 KiB 904.25 KiB
ee17551 23.75 KiB 928.53 KiB 904.78 KiB
621c433 23.75 KiB 928.56 KiB 904.81 KiB
289850d 23.75 KiB 928.00 KiB 904.25 KiB

@noahsmartin noahsmartin force-pushed the updateApplication branch 2 times, most recently from 0a54d3f to fc48fe4 Compare August 13, 2025 12:47
@noahsmartin noahsmartin marked this pull request as ready for review August 13, 2025 12:51
cursor[bot]

This comment was marked as outdated.

@ohwhen
Copy link

ohwhen commented Aug 13, 2025

🔥

Copy link
Member

@philprime philprime left a comment

Choose a reason for hiding this comment

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

Good progress, let some comments

@noahsmartin noahsmartin force-pushed the updateApplication branch 2 times, most recently from 4d434eb to b117726 Compare August 28, 2025 22:10
Copy link
Member

@philprime philprime left a comment

Choose a reason for hiding this comment

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

LGTM

@noahsmartin noahsmartin force-pushed the updateApplication branch 2 times, most recently from 3438ca1 to e417f85 Compare September 4, 2025 17:30
Copy link
Contributor

github-actions bot commented Sep 4, 2025

🚨 Detected changes in high risk code 🚨

High-risk code can easily blow up and is hard to test. We had severe bugs in the past. Be extra careful when changing these files, and have an extra careful look at these:

  • Sources/Sentry/SentryUIViewControllerSwizzling.m

@noahsmartin noahsmartin merged commit c174e5e into main Sep 4, 2025
229 of 239 checks passed
@noahsmartin noahsmartin deleted the updateApplication branch September 4, 2025 22:06
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.

3 participants