Skip to content

Commit f938d24

Browse files
authored
fix: synchronize and copy global profiling data structures (#3018)
1 parent b7bd719 commit f938d24

File tree

8 files changed

+406
-216
lines changed

8 files changed

+406
-216
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixed
6+
7+
- Fix crashes in profiling serialization race condition (#3018)
8+
39
## 8.7.1
410

511
### Features

Sources/Sentry/SentryProfileTimeseries.mm

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
# import "SentryLog.h"
88
# import "SentryTransaction.h"
99

10-
std::mutex _gSamplesArrayLock;
11-
1210
/**
1311
* Print a debug log to help diagnose slicing errors.
1412
* @param start @c YES if this is an attempt to find the start of the sliced data based on the
@@ -44,51 +42,45 @@
4442
NSArray<SentrySample *> *_Nullable slicedProfileSamples(
4543
NSArray<SentrySample *> *samples, SentryTransaction *transaction)
4644
{
47-
NSArray<SentrySample *> *samplesCopy;
48-
{
49-
std::lock_guard<std::mutex> l(_gSamplesArrayLock);
50-
samplesCopy = [samples copy];
51-
}
52-
53-
if (samplesCopy.count == 0) {
45+
if (samples.count == 0) {
5446
return nil;
5547
}
5648

5749
const auto transactionStart = transaction.startSystemTime;
5850
const auto firstIndex =
59-
[samplesCopy indexOfObjectWithOptions:NSEnumerationConcurrent
60-
passingTest:^BOOL(SentrySample *_Nonnull sample, NSUInteger idx,
61-
BOOL *_Nonnull stop) {
62-
*stop = sample.absoluteTimestamp >= transactionStart;
63-
return *stop;
64-
}];
51+
[samples indexOfObjectWithOptions:NSEnumerationConcurrent
52+
passingTest:^BOOL(SentrySample *_Nonnull sample, NSUInteger idx,
53+
BOOL *_Nonnull stop) {
54+
*stop = sample.absoluteTimestamp >= transactionStart;
55+
return *stop;
56+
}];
6557

6658
if (firstIndex == NSNotFound) {
67-
logSlicingFailureWithArray(samplesCopy, transaction, /*start*/ YES);
59+
logSlicingFailureWithArray(samples, transaction, /*start*/ YES);
6860
return nil;
6961
} else {
7062
SENTRY_LOG_DEBUG(@"Found first slice sample at index %lu", firstIndex);
7163
}
7264

7365
const auto transactionEnd = transaction.endSystemTime;
7466
const auto lastIndex =
75-
[samplesCopy indexOfObjectWithOptions:NSEnumerationConcurrent | NSEnumerationReverse
76-
passingTest:^BOOL(SentrySample *_Nonnull sample, NSUInteger idx,
77-
BOOL *_Nonnull stop) {
78-
*stop = sample.absoluteTimestamp <= transactionEnd;
79-
return *stop;
80-
}];
67+
[samples indexOfObjectWithOptions:NSEnumerationConcurrent | NSEnumerationReverse
68+
passingTest:^BOOL(SentrySample *_Nonnull sample, NSUInteger idx,
69+
BOOL *_Nonnull stop) {
70+
*stop = sample.absoluteTimestamp <= transactionEnd;
71+
return *stop;
72+
}];
8173

8274
if (lastIndex == NSNotFound) {
83-
logSlicingFailureWithArray(samplesCopy, transaction, /*start*/ NO);
75+
logSlicingFailureWithArray(samples, transaction, /*start*/ NO);
8476
return nil;
8577
} else {
8678
SENTRY_LOG_DEBUG(@"Found last slice sample at index %lu", lastIndex);
8779
}
8880

8981
const auto range = NSMakeRange(firstIndex, (lastIndex - firstIndex) + 1);
9082
const auto indices = [NSIndexSet indexSetWithIndexesInRange:range];
91-
return [samplesCopy objectsAtIndexes:indices];
83+
return [samples objectsAtIndexes:indices];
9284
}
9385

9486
@implementation SentrySample

0 commit comments

Comments
 (0)