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

Check MACH_PORT_VALID on return from pthread_mach_thread_np #3520

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

indragiek
Copy link
Member

📜 Description

pthread_mach_thread_np can return invalid values so check for those and return nullptr from ThreadHandle. That means changing the call sites for ThreadHandle::current() to check for a null pointer value.

💡 Motivation and Context

We don't have a solid repro for #3354 but this is one of the potential causes. In any case it doesn't hurt to add the check.

💚 How did you test it?

Run tests

📝 Checklist

You have to check all boxes before merging:

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

pthread_mach_thread_np can return invalid values so check for those and return nullptr from ThreadHandle
@indragiek indragiek force-pushed the indragiek/pthread_mach_thread_np-null branch from 6990048 to b656bde Compare December 27, 2023 21:16
Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

@indragiek, good catch 👍 . CI is broken, and it would be great to add or change some tests for these changes if possible.

Sources/Sentry/SentryThreadHandle.cpp Outdated Show resolved Hide resolved
Sources/Sentry/include/SentryThreadHandle.hpp Outdated Show resolved Hide resolved
Copy link
Member

@armcknight armcknight left a comment

Choose a reason for hiding this comment

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

Reading the logic again in SentryBacktrace.cpp which contains the callsite for the function we've modified is a bit unclear to me, given the name allExcludingCurrent. Reading it starting at the loop, it looks like we're going to do work on all the other threads except the current one, which is true, but we do still have to retain the current thread in order to know what thread we're running on, and the callsite tells me we threw out that info when we actually didn't.

TL;DR I would propose we rename allExcludingCurrent to currentAndOtherThreads.

Sources/Sentry/SentryThreadHandle.cpp Outdated Show resolved Hide resolved
Sources/Sentry/include/SentryThreadHandle.hpp Outdated Show resolved Hide resolved
Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

Once we have some tests, I will approve this PR. The rest LGTM.

Copy link

codecov bot commented Jun 20, 2024

Codecov Report

Attention: Patch coverage is 81.13208% with 10 lines in your changes missing coverage. Please review.

Project coverage is 91.165%. Comparing base (1734d1b) to head (6fac4d6).
Report is 343 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #3520       +/-   ##
=============================================
+ Coverage   89.241%   91.165%   +1.923%     
=============================================
  Files          529       609       +80     
  Lines        57780     47846     -9934     
  Branches     20687         0    -20687     
=============================================
- Hits         51564     43619     -7945     
+ Misses        5300      4227     -1073     
+ Partials       916         0      -916     
Files Coverage Δ
Sources/Sentry/PrivateSentrySDKOnly.mm 90.714% <100.000%> (+3.558%) ⬆️
Sources/Sentry/SentryThreadHandle.cpp 62.727% <100.000%> (-6.504%) ⬇️
Sources/Sentry/SentryTransactionContext.mm 100.000% <100.000%> (ø)
...yCrash/Recording/Monitors/SentryCrashMonitorType.c 0.000% <ø> (ø)
...entryCrash/Recording/Tools/SentryCrashSignalInfo.c 100.000% <ø> (ø)
...sts/SentryProfilerTests/SentryThreadHandleTests.mm 95.789% <100.000%> (+2.932%) ⬆️
Tests/SentryTests/SentryCrash/CrashReport.swift 100.000% <100.000%> (+6.666%) ⬆️
Tests/SentryTests/SentryInterfacesTests.m 100.000% <100.000%> (ø)
...rding/Monitors/SentryCrashMonitor_CPPException.cpp 20.408% <0.000%> (-10.223%) ⬇️
Tests/SentryProfilerTests/SentryBacktraceTests.mm 95.744% <88.888%> (+0.939%) ⬆️
... and 2 more

... and 607 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 1734d1b...6fac4d6. Read the comment docs.

Copy link

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1208.50 ms 1221.08 ms 12.58 ms
Size 21.58 KiB 671.08 KiB 649.50 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
52e4912 1216.25 ms 1226.69 ms 10.44 ms
742d4b6 1230.41 ms 1247.23 ms 16.83 ms
297f460 1234.81 ms 1255.27 ms 20.45 ms
becc941 1221.90 ms 1240.37 ms 18.47 ms
340fb46 1224.60 ms 1239.27 ms 14.67 ms
3297d6e 1195.69 ms 1212.35 ms 16.65 ms
0d32275 1215.31 ms 1240.19 ms 24.88 ms
4d3df92 1218.27 ms 1248.30 ms 30.03 ms
b15521e 1224.44 ms 1251.13 ms 26.68 ms
e5dcbd5 1223.47 ms 1243.90 ms 20.43 ms

App size

Revision Plain With Sentry Diff
52e4912 21.58 KiB 418.14 KiB 396.56 KiB
742d4b6 21.58 KiB 546.20 KiB 524.62 KiB
297f460 21.58 KiB 629.83 KiB 608.24 KiB
becc941 21.58 KiB 419.82 KiB 398.24 KiB
340fb46 21.58 KiB 418.78 KiB 397.20 KiB
3297d6e 21.58 KiB 418.44 KiB 396.86 KiB
0d32275 22.84 KiB 403.14 KiB 380.29 KiB
4d3df92 22.85 KiB 413.45 KiB 390.60 KiB
b15521e 21.58 KiB 573.18 KiB 551.60 KiB
e5dcbd5 22.85 KiB 414.09 KiB 391.24 KiB

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.

None yet

4 participants