sentry-cocoa icon indicating copy to clipboard operation
sentry-cocoa copied to clipboard

Uncaught exception in `slicedProfileSamples`

Open jpsim opened this issue 2 years ago • 3 comments

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

jpsim avatar Dec 07 '23 02:12 jpsim

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?

philipphofmann avatar Dec 07 '23 14:12 philipphofmann

@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.

armcknight avatar Dec 11 '23 23:12 armcknight

@zhou934381967 shared a detailed error message in https://github.com/getsentry/sentry-cocoa/issues/3509, which I closed as a duplicate: image

philipphofmann avatar Dec 19 '23 14:12 philipphofmann