-
Notifications
You must be signed in to change notification settings - Fork 130
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 potential deadlock when generating a crash report #580
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 tasks
robinmacharg
force-pushed
the
fix-dyld-deadlock2
branch
3 times, most recently
from
May 4, 2020 16:08
6ac538e
to
678db0c
Compare
robinmacharg
force-pushed
the
fix-dyld-deadlock2
branch
from
May 5, 2020 08:10
678db0c
to
129bd04
Compare
tomlongridge
requested changes
May 5, 2020
Source/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSMachHeaders.m
Outdated
Show resolved
Hide resolved
Source/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSMachHeaders.m
Outdated
Show resolved
Hide resolved
Source/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSMachHeaders.m
Outdated
Show resolved
Hide resolved
Source/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSMachHeaders.m
Outdated
Show resolved
Hide resolved
Source/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSMachHeaders.h
Outdated
Show resolved
Hide resolved
Source/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSMachHeaders.m
Outdated
Show resolved
Hide resolved
robinmacharg
force-pushed
the
fix-dyld-deadlock2
branch
from
May 5, 2020 11:11
bc21cc7
to
ea3cc67
Compare
tomlongridge
reviewed
May 5, 2020
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.
I'm happy, apart from two small nits.
@fractalwrench - can you take a look?
Source/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSMachHeaders.h
Outdated
Show resolved
Hide resolved
Source/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSMachHeaders.m
Outdated
Show resolved
Hide resolved
Source/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSMachHeaders.h
Outdated
Show resolved
Hide resolved
Source/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSMachHeaders.m
Outdated
Show resolved
Hide resolved
Source/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSMachHeaders.m
Outdated
Show resolved
Hide resolved
Source/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSMachHeaders.m
Outdated
Show resolved
Hide resolved
Source/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSMachHeaders.m
Outdated
Show resolved
Hide resolved
Source/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSMachHeaders.m
Outdated
Show resolved
Hide resolved
Source/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSMachHeaders.h
Outdated
Show resolved
Hide resolved
tomlongridge
reviewed
May 6, 2020
Source/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSMachHeaders.m
Outdated
Show resolved
Hide resolved
robinmacharg
force-pushed
the
fix-dyld-deadlock2
branch
from
May 6, 2020 12:39
4494af7
to
84663b5
Compare
fractalwrench
approved these changes
May 6, 2020
tomlongridge
approved these changes
May 6, 2020
robinmacharg
added
awaiting feedback
Awaiting a response from a customer. Will be automatically closed after approximately 2 weeks.
bug
Confirmed bug
wip
There is work in progress
labels
May 6, 2020
robinmacharg
added
scheduled
Work is starting on this feature/bug
and removed
wip
There is work in progress
labels
May 6, 2020
fractalwrench
approved these changes
May 12, 2020
Source/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSMachHeaders.h
Outdated
Show resolved
Hide resolved
Source/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSDynamicLinker.c
Outdated
Show resolved
Hide resolved
Source/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSMachHeaders.h
Outdated
Show resolved
Hide resolved
Source/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSMachHeaders.h
Outdated
Show resolved
Hide resolved
tomlongridge
approved these changes
May 12, 2020
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 👍
robinmacharg
removed
the
awaiting feedback
Awaiting a response from a customer. Will be automatically closed after approximately 2 weeks.
label
May 13, 2020
robinmacharg
force-pushed
the
fix-dyld-deadlock2
branch
from
May 13, 2020 10:46
d9fb1ad
to
89aa9a1
Compare
fractalwrench
approved these changes
May 13, 2020
tomlongridge
approved these changes
May 13, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
[Note: this PR supersedes #577, and incorporates feedback from initial review.]
Goal
An issue has been identified that can lead to an app deadlocking when reporting a crash.
The sequence of events is:
dyld
and takes a lock out.dyld
lock.This PR fixes this issue.
Design
There are two main mechanisms by which a program may find out about
dyld
behaviour: by direct querying (e.g._dyld_get_image_header()
etc., used by the KSCrash component of Bugsnag prior to this issue) and by callback (_dyld_register_func_for_add_image()
etc.). This change modifies the KSCrash component to use callbacks and caches information about loaded binary images for when a crash does occur. Thus, when threads are suspended and a crash report is generated no additional calls todyld
need to be made and deadlock is avoided.Thread safety is a concern. Reading the released dyld source code implies that access to the internal binary image storage in modern OS releases is mediated by a locking mechanism. However to date no documented guarantee of this has been found. For the avoidance of doubt the KSCrash-level
add/remove
callbacks use a legacy-compatible shared lock to ensure synchronisation. By the time a crash report is being written all other non-KS threads will have been suspended and so no additional locking is required.Performance is also a concern, especially given that the proposed solution moves processing from post-crash (where users are likely to be less concerned about a couple of lost seconds) to up-front. The library startup code was crudely timed in the sample iOS app on a real device (iPhone XS), with results as follows:
i.e. a difference of ~2ms. This was for 385 binary images. (Anecdotally, turning on debugging adds ~0.1s to the startup time).
Changeset
dyld
binary image capture was moved fromBSG_KSCrashReport.c
toBSG_KSCrash.m
. A file-static dynamic array cache is used. An additional.m
file contains functions to ease bridging between Objective C and C.Bugsnag/KSCrash makes use of
dyld
in two main - but related - places:BSG_KSCrashReport.c
writing andBSG_KSDynamicLinker.c
. These were modified to use an internal API similar to that presented bydyld
that accesses the cache of headers.Tests
json
reports are have been manually tested.Review
Outstanding Questions
master
for fixes,next
forfeatures)