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-7101 ] Fix ThreadSanitizer data race in BugsnagBreadcrumbs #1160

Merged
merged 1 commit into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Bugsnag/Breadcrumbs/BugsnagBreadcrumbs.m
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,11 @@ - (void)addBreadcrumbWithData:(NSData *)data writeToDisk:(BOOL)writeToDisk {
dispatch_async(BSGGlobalsFileSystemQueue(), ^{
// Avoid writing breadcrumbs that have already been deleted from the in-memory store.
// This can occur when breadcrumbs are being added faster than they can be written.
unsigned int nextFileNumber = self.nextFileNumber;
BOOL isStale = (self.maxBreadcrumbs < nextFileNumber) && (fileNumber < (nextFileNumber - self.maxBreadcrumbs));
BOOL isStale;
@synchronized (self) {
unsigned int nextFileNumber = self.nextFileNumber;
isStale = (self.maxBreadcrumbs < nextFileNumber) && (fileNumber < (nextFileNumber - self.maxBreadcrumbs));
}

NSError *error = nil;

Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

## TBD

### Bug fixes

* Fix ThreadSanitizer data race in `BugsnagBreadcrumbs`.
[#1160](https://github.com/bugsnag/bugsnag-cocoa/pull/1160)

## 6.10.3 (2021-08-04)

### Bug fixes
Expand Down
4 changes: 4 additions & 0 deletions Tests/BugsnagBreadcrumbsTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@ - (void)testCrashReportWriter {
}

- (void)testCrashReportWriterConcurrency {
#if defined(__has_feature) && __has_feature(thread_sanitizer)
NSLog(@"Skipping test because ThreadSanitizer deadlocks if other threads are suspended");
return;
#endif
//
// The aim of this test is to ensure that BugsnagBreadcrumbsWriteCrashReport will insert only valid JSON
// into a crash report when other threads are (paused while) updating the breadcrumbs linked list.
Expand Down