Skip to content

Commit 13d5b25

Browse files
authored
Merge a3c542c into 1bf8571
2 parents 1bf8571 + a3c542c commit 13d5b25

File tree

9 files changed

+300
-185
lines changed

9 files changed

+300
-185
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ This change has no impact on grouping of the issues in Sentry.
3030

3131
- Propagate span when copying scope (#2952)
3232
- Remove "/" from crash report file name (#3005)
33+
- Fix race condition in profiling serialization (#3018)
3334

3435
## 8.6.0
3536

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)