-
-
Notifications
You must be signed in to change notification settings - Fork 330
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: Remove dispatch queue metadata collection to fix crash #3522
Conversation
…y/sentry-cocoa into indragiek/remove-queue-metadata
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3522 +/- ##
=============================================
+ Coverage 89.241% 89.258% +0.016%
=============================================
Files 529 529
Lines 57780 57718 -62
Branches 20687 20659 -28
=============================================
- Hits 51564 51518 -46
+ Misses 5300 5288 -12
+ Partials 916 912 -4
... and 9 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
Performance metrics 🚀
|
Revision | Plain | With Sentry | Diff |
---|---|---|---|
c0ff306 | 1219.24 ms | 1243.96 ms | 24.72 ms |
9883c0f | 1207.59 ms | 1223.14 ms | 15.55 ms |
313b1d9 | 1240.18 ms | 1258.44 ms | 18.26 ms |
034be1c | 1222.67 ms | 1236.22 ms | 13.55 ms |
156e771 | 1228.06 ms | 1242.64 ms | 14.58 ms |
e2abb0d | 1235.08 ms | 1257.00 ms | 21.92 ms |
216bdf9 | 1199.84 ms | 1209.53 ms | 9.69 ms |
b9a9ffd | 1221.18 ms | 1235.37 ms | 14.19 ms |
a9103fe | 1221.49 ms | 1243.33 ms | 21.84 ms |
3f6c30b | 1252.98 ms | 1266.22 ms | 13.24 ms |
App size
Revision | Plain | With Sentry | Diff |
---|---|---|---|
c0ff306 | 20.76 KiB | 434.65 KiB | 413.89 KiB |
9883c0f | 22.85 KiB | 405.47 KiB | 382.62 KiB |
313b1d9 | 22.85 KiB | 414.11 KiB | 391.26 KiB |
034be1c | 20.76 KiB | 436.66 KiB | 415.90 KiB |
156e771 | 20.76 KiB | 419.70 KiB | 398.94 KiB |
e2abb0d | 20.76 KiB | 434.72 KiB | 413.96 KiB |
216bdf9 | 21.58 KiB | 418.13 KiB | 396.54 KiB |
b9a9ffd | 21.58 KiB | 418.43 KiB | 396.85 KiB |
a9103fe | 20.76 KiB | 426.95 KiB | 406.19 KiB |
3f6c30b | 22.85 KiB | 408.88 KiB | 386.03 KiB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks @indragiek 👍
if (!backtrace.threadMetadata.name.empty() && metadata[@"name"] == nil) { | ||
metadata[@"name"] = | ||
[NSString stringWithUTF8String:backtrace.threadMetadata.name.c_str()]; | ||
if (metadata[@"name"] == nil) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m
: I think we shoud first check if backtrace.threadMetadata.threadID == self->_mainThreadID
. Otherwise, the main thread could have different names depending on the platform. Or is this the desired behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it's checking if it's already been set previously, as we reuse the metadata dictionary. The check you mention does happen before we actually go to set the value on line 107 below in this hunk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah @armcknight is right, that was the intent here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
if ([NSThread isMainThread]) { | ||
[self cacheMainThreadID]; | ||
} else { | ||
dispatch_async(dispatch_get_main_queue(), ^{ [self cacheMainThreadID]; }); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a wrapper for this, i pushed commit 9fbdeb6 to use it
} | ||
} else { | ||
XCTAssertFalse(try XCTUnwrap(try XCTUnwrap(queueMetadata.first?.value)["label"] as? String).isEmpty) | ||
XCTAssertFalse(try threadMetadata.values.compactMap { $0["name"] }.filter { try XCTUnwrap($0 as? String) == "main" }.isEmpty) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, this probably should have been there before, but thanks for adding it 👍🏻
I logged the thread sanitizer warning in a new issue, I don't think it's related. |
* Remove dispatch queue metadata collection * Hardcode "main" as the name of the main thread * Format code * Update CHANGELOG.md * use thread wrapper main thread dispatch --------- Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io> Co-authored-by: Andrew McKnight <andrew.mcknight@sentry.io>
📜 Description
This PR removes the collection of dispatch queue metadata when profiling, and uses
main
as the hard-coded thread name for the main thread (in place of the queue namecom.apple.main-thread
) for consistency with other platforms.💡 Motivation and Context
We have crashes in production from trying to read
ThreadHandle::dispatchQueueAddress
when profiling: #3503This appears to be a race condition with queue lifetime that is not possible to fully fix. There are similar problems encountered by other projects trying to use the same API:
💚 How did you test it?
Updated the tests, checked that the hardcoded
main
thread name is set.📝 Checklist
You have to check all boxes before merging:
sendDefaultPII
is enabled.🔮 Next steps