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

[PLAT-8643] Fix a rare crash in BugsnagBreadcrumbsWriteCrashReport() #1430

Merged
merged 1 commit into from
Jul 11, 2022

Conversation

nickdowell
Copy link
Contributor

Goal

Fix a rare crash that has been observed in BugsnagBreadcrumbsWriteCrashReport().

A small number of crashes have been seen with the signature:

EXC_BAD_ACCESS

0 libsystem_platform.dylib _platform_strlen
1 Bugsnag                  bsg_kscrw_i_addJSONElement
2 Bugsnag                  BugsnagBreadcrumbsWriteCrashReport
3 Bugsnag                  BSSerializeDataCrashHandler
4 Bugsnag                  bsg_kscrashreport_writeStandardReport
5 Bugsnag                  ksmachexc_i_handleExceptions
6 libsystem_pthread.dylib  _pthread_start

... which appears to be due to BugsnagBreadcrumbsWriteCrashReport() accessing breadcrumbs that have been freed.

In theory this should not occur, because all possible writer threads should be suspended while this function runs, but it's possible that a call to thread_suspend fails or a thread is spawned after the thread list has been captured, leading to an active writer.

Changeset

Adds an atomic_bool to prevent memory being freed while BugsnagBreadcrumbsWriteCrashReport() is running, and makes g_breadcrumbs_head atomic to ensure it is fully stored before memory is freed.

Testing

Amends -testCrashReportWriterConcurrency to verify that BugsnagBreadcrumbsWriteCrashReport() is safe to call while writer threads are running.

@github-actions
Copy link

Bugsnag.framework binary size increased by 80 bytes from 815,832 to 815,912

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +72  +0.0%     +72    __TEXT,__text
  +0.0%     +48  +0.0%     +48    String Table
  +0.0%     +32  +0.0%     +32    Symbol Table
  [ = ]       0  +0.1%      +8    __DATA,__bss
  +0.2%      +8  +0.2%      +8    __TEXT,__gcc_except_tab
  +0.1%      +4  +0.1%      +4    __TEXT,__unwind_info
  [ = ]       0  -0.1%      -8    [__DATA]
  [ = ]       0  -2.4%     -80    [__LINKEDIT]
  -0.4%     -84  -0.4%     -84    [__TEXT]
  +0.0%     +80  [ = ]       0    TOTAL

Generated by 🚫 Danger

@nickdowell nickdowell merged commit 5067239 into next Jul 11, 2022
@nickdowell nickdowell deleted the nickdowell/breadcrumb-thread-safety branch July 11, 2022 14:56
@nickdowell nickdowell mentioned this pull request Jul 13, 2022
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.

2 participants