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: Crash for Call Should be on Main Thread #1371

Merged
merged 10 commits into from
Oct 12, 2021

Conversation

philipphofmann
Copy link
Member

@philipphofmann philipphofmann commented Oct 12, 2021

📜 Description

The swizzling of subclasses of UIViewController stored
references to classes on a background thread, which led
to calling the initialize method. Some UIViewControllers
implementing assume that they are on the main thread
when executing initialize. Calling initialize from a
background thread can lead to crashes. This is fixed now
by avoiding the call to initialize on a background thread and
swizzling on the main thread.

💡 Motivation and Context

Fixes GH-1366

💚 How did you test it?

Unit tests, UI tests, on a real device and with the sample project pointed out in GH-1366.

📝 Checklist

  • I reviewed the submitted code
  • I added tests to verify the changes
  • I updated the docs if needed
  • Review from the native team if needed
  • No breaking changes

🔮 Next steps

The swizzling of subclasses of UIViewController stored
references to classes on a background thread, which led
to calling the initialize method. Some UIViewControllers
implementing assume that they are on the main thread
when executing initialize. Calling initialize from a
background thread can lead to crashes. This is fixed now
by avoiding the call to initialize on a background thread and
swizzling on the main thread.

Fixes GH-1366
@philipphofmann philipphofmann requested review from brustolin and a team October 12, 2021 12:40
@philipphofmann philipphofmann marked this pull request as draft October 12, 2021 12:45
@philipphofmann philipphofmann marked this pull request as ready for review October 12, 2021 12:55
Copy link
Contributor

@brustolin brustolin left a comment

Choose a reason for hiding this comment

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

LGTM

testAsyncStacktraces should be testing if stack traces of different threads
are stitched together, which it didn't do, because we were only building
the stack trace on the main thread. This is fixed now by building the
stack trace across different threads. Furthermore, the tests now use
its own queue to avoid side effects when testing.
philipphofmann and others added 6 commits October 12, 2021 16:38
testAsyncStacktraces should be testing if stack traces of different threads
are stitched together, which it didn't do, because we were only building
the stack trace on the main thread. This is fixed now by building the
stack trace across different threads. Furthermore, the tests now use
its own queue to avoid side effects when testing.
@codecov-commenter
Copy link

codecov-commenter commented Oct 12, 2021

Codecov Report

Merging #1371 (d8d1807) into master (dfce484) will increase coverage by 0.15%.
The diff coverage is 96.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1371      +/-   ##
==========================================
+ Coverage   95.45%   95.60%   +0.15%     
==========================================
  Files         153      152       -1     
  Lines        5500     5509       +9     
==========================================
+ Hits         5250     5267      +17     
+ Misses        250      242       -8     
Impacted Files Coverage Δ
Sources/Sentry/SentryUIViewControllerSwizziling.m 74.46% <96.00%> (+5.97%) ⬆️
Sources/Sentry/SentryDispatchQueueWrapper.m 100.00% <100.00%> (ø)
Sources/Sentry/SentryNetworkTrackingIntegration.m 100.00% <0.00%> (+7.40%) ⬆️
Sources/Sentry/SentryStacktraceBuilder.m 100.00% <0.00%> (+12.50%) ⬆️
Sources/Sentry/SentryCrashAdapter.m 84.61% <0.00%> (+15.38%) ⬆️

Continue to review full report at Codecov.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Call must be made on main thread
4 participants