sentry-cocoa
sentry-cocoa copied to clipboard
Uncaught exception in `slicedProfileSamples`
Platform
iOS
Environment
Develop
Installed
Swift Package Manager
Version
8.17.1
Did it work on previous versions?
Yes 8.15
Steps to Reproduce
Will work on more comprehensive steps to repro async, but for now at least wanted to get this on your radar.
Expected Result
Ability to call -[SentryTracer finishWithStatus:] without triggering internal exceptions. I reported a similar issue in https://github.com/getsentry/sentry-cocoa/issues/3299 which appeared to have been fixed in 8.15, but now I'm seeing a different exception thrown from the same Sentry API.
Actual Result
0 CoreFoundation 0x18049111c __exceptionPreprocess + 160
1 libobjc.A.dylib 0x18008412c objc_exception_throw + 56
2 CoreFoundation 0x180479590 -[NSArray objectsAtIndexes:] + 1092
3 MyApp 0x1079ba134 slicedProfileSamples(NSArray<SentrySample*>*, unsigned long long, unsigned long long) + 1552
4 MyApp 0x1079bbae8 serializedProfileData(NSDictionary<NSString*, objc_object*>*, unsigned long long, unsigned long long, NSString*, NSDictionary<NSString*, objc_object*>*, NSArray<SentryDebugMeta*>*, SentryHub*, SentryScreenFrames*) + 964
5 MyApp 0x1079bf0ec -[SentryProfiler serializeBetween:and:onHub:] + 316
6 MyApp 0x1079be630 +[SentryProfiler collectProfileBetween:and:forTrace:onHub:] + 176
7 MyApp 0x1079be07c +[SentryProfiler createProfilingEnvelopeItemForTransaction:] + 252
8 MyApp 0x1079f26a0 -[SentryTracer captureTransactionWithProfile:] + 76
9 MyApp 0x1079f24ec -[SentryTracer finishInternal] + 2356
10 MyApp 0x1079f18d8 -[SentryTracer canBeFinished] + 1196
11 MyApp 0x1079f1420 -[SentryTracer finishWithStatus:] + 448
Are you willing to submit a PR?
Yes, if I can figure out a fix
I see a couple of crashes in our internal SDK crash detection.
The crash occurs here at objectsAtIndexes https://github.com/getsentry/sentry-cocoa/blob/ddb47781bffd76406f31ab43e66760362585fcd7/Sources/Sentry/SentryProfileTimeseries.mm#L79-L81
My first thought was that maybe our code modifies samples while reading from it, but we correctly make a copy of the samples before we access them here https://github.com/getsentry/sentry-cocoa/blob/ddb47781bffd76406f31ab43e66760362585fcd7/Sources/Sentry/Profiling/SentryProfilerState.mm#L158-L162
Maybe we miss some edge cases when calculating the indices, @armcknight?
@jpsim thanks for reporting, and sorry you're still seeing issues. Hoping to get some more info from you:
- could you let me know what exception you're seeing? Our own crash reports show
NSGenericException. I'm wondering if you see the same, or if you're seeing NSRangeExceptions. - could you share how many of these you're seeing and in what time frame? Our reports show a handful per two-week period.
@zhou934381967 shared a detailed error message in https://github.com/getsentry/sentry-cocoa/issues/3509, which I closed as a duplicate: