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

the iOS app crashed on Sentry SDK [SentrySerialization dataWithJSONObject:] #3050

Closed
Mohsenkhodadadzadehthelist opened this issue May 22, 2023 · 14 comments

Comments

@Mohsenkhodadadzadehthelist

Platform

iOS

Installed

Swift Package Manager

Version

8.7.1

Steps to Reproduce

we are using Sentry for our product since 3 days ago and the firebase crashlytics reported to us we had 3 crashes on the Sentry SDK

Expected Result

work properly without crash

Actual Result

The first one :
+[SentrySerialization dataWithJSONObject:]
NSInvalidArgumentException - Invalid type in JSON write ((null))

Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x9d94 __exceptionPreprocess
1  libobjc.A.dylib                0x183d0 objc_exception_throw
2  Foundation                     0x2e61c _writeJSONValue
3  Foundation                     0xd4a70 ___writeJSONArray_block_invoke
4  CoreFoundation                 0xa2ac __NSARRAY_IS_CALLING_OUT_TO_A_BLOCK__
5  CoreFoundation                 0x25904 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:]
6  Foundation                     0xa8d98 _writeJSONArray
7  Foundation                     0xc627c ___writeJSONObject_block_invoke
8  CoreFoundation                 0x1377c __NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK__
9  CoreFoundation                 0xc0e94 -[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:]
10 Foundation                     0x27f70 _writeJSONObject
11 Foundation                     0xc627c ___writeJSONObject_block_invoke
12 CoreFoundation                 0x1377c __NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK__
13 CoreFoundation                 0x9c1e0 -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:]
14 Foundation                     0x27f70 _writeJSONObject
15 Foundation                     0x514cc -[_NSJSONWriter dataWithRootObject:options:]
16 Foundation                     0x50f00 +[NSJSONSerialization dataWithJSONObject:options:error:]
17 Sentry                         0x69678 +[SentrySerialization dataWithJSONObject:] + 27 (SentrySerialization.m:27)
18 Sentry                         0x5f918 +[SentryProfiler envelopeItemForProfileData:profileID:] + 739 (SentryProfiler.mm:739)
19 Sentry                         0x5d2a4 +[SentryProfiler createProfilingEnvelopeItemForTransaction:] + 439 (SentryProfiler.mm:439)
20 Sentry                         0x7748c -[SentryTracer captureTransactionWithProfile:] + 511 (SentryTracer.m:511)
21 Sentry                         0x77260 -[SentryTracer finishInternal] + 499 (SentryTracer.m:499)
22 Sentry                         0x59de8 -[SentryPerformanceTracker finishSpan:withStatus:] + 204 (SentryPerformanceTracker.m:204)
23 Sentry                         0x7e3a0 __102-[SentryUIViewControllerPerformanceTracker finishTransaction:status:lifecycleMethod:callbackToOrigin:]_block_invoke + 260 (SentryUIViewControllerPerformanceTracker.m:260)
24 Sentry                         0x7eb38 -[SentryUIViewControllerPerformanceTracker limitOverride:target:callbackToOrigin:block:] + 379 (SentryUIViewControllerPerformanceTracker.m:379)
25 Sentry                         0x7e1e0 -[SentryUIViewControllerPerformanceTracker finishTransaction:status:lifecycleMethod:callbackToOrigin:] + 270 (SentryUIViewControllerPerformanceTracker.m:270)
26 Sentry                         0x7e0d4 -[SentryUIViewControllerPerformanceTracker viewControllerViewDidAppear:callbackToOrigin:] + 198 (SentryUIViewControllerPerformanceTracker.m:198)
27 Sentry                         0x810cc __56-[SentryUIViewControllerSwizzling swizzleViewDidAppear:]_block_invoke_2 + 400 (SentryUIViewControllerSwizzling.m:400)
28 Instabug                       0x121bac __36-[IBGSubclassSwizzler swizzleClass:]_block_invoke.705
29 UIKitCore                      0xd73c -[UIViewController _setViewAppearState:isAnimating:]
30 UIKitCore                      0x220f4c -[UIViewController __viewDidAppear:]
31 UIKitCore                      0x220e2c __64-[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]_block_invoke
32 UIKitCore                      0x1a04ec -[UIViewController _executeAfterAppearanceBlock]
33 UIKitCore                      0x1a0430 -[_UIAfterCACommitBlock run]
34 UIKitCore                      0x1a0364 -[_UIAfterCACommitQueue flush]
35 UIKitCore                      0x1a0278 _runAfterCACommitDeferredBlocks
36 UIKitCore                      0x3eee4 _cleanUpAfterCAFlushAndRunDeferredBlocks
37 UIKitCore                      0x4fd608 _UIApplicationFlushCATransaction
38 UIKitCore                      0x64de00 _UIUpdateSequenceRun
39 UIKitCore                      0xcb1944 schedulerStepScheduledMainSection
40 UIKitCore                      0xcb0ea0 runloopSourceCallback
41 CoreFoundation                 0xd3208 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
42 CoreFoundation                 0xdf864 __CFRunLoopDoSource0
43 CoreFoundation                 0x646c8 __CFRunLoopDoSources0
44 CoreFoundation                 0x7a1c4 __CFRunLoopRun
45 CoreFoundation                 0x7f4dc CFRunLoopRunSpecific
46 GraphicsServices               0x135c GSEventRunModal
47 UIKitCore                      0x39d37c -[UIApplication _run]
48 UIKitCore                      0x39cfe0 UIApplicationMain
49 thelist                        0x5760 main + 14 (AppDelegate.swift:14)
50 ???                            0x1dbb58dec (Missing)

and the device information:
Device Model:iPhone 14 Pro
Orientation:Portrait
RAM free: 79.48 MB
Disk free: 125.62 GB
Operating system Version:16.4.1
Jailbroken:No


the second one is

-[SentryScreenshot takeScreenshots]
SIGABRT (ABORT)

Crashed: SentryCrash Exception Handler (Primary)
0  libsystem_kernel.dylib         0x6bbc __pthread_kill + 8
1  libsystem_pthread.dylib        0xd844 pthread_kill + 208
2  libsystem_c.dylib              0x1f6ac abort + 124
3  libsystem_malloc.dylib         0x1b9d8 _malloc_put + 546
4  libsystem_malloc.dylib         0x1bc40 malloc_zone_error + 96
5  libsystem_malloc.dylib         0x1007c nanov2_allocate_from_block$VARIANT$mp + 544
6  libsystem_malloc.dylib         0xf280 nanov2_allocate$VARIANT$mp + 124
7  libsystem_malloc.dylib         0xf1b4 nanov2_malloc$VARIANT$mp + 60
8  libsystem_malloc.dylib         0x5efc _malloc_zone_malloc + 148
9  CoreFoundation                 0x2a02c _CFRuntimeCreateInstance + 568
10 CoreGraphics                   0x1924 CGTypeCreateInstance + 52
11 CoreGraphics                   0x47c4c CGColorTransformCreate + 232
12 CoreGraphics                   0x34378 __CGBitmapContextDelegateCreate + 376
13 CoreGraphics                   0x10e68 bitmap_context_create + 176
14 CoreGraphics                   0x34670 CGBitmapContextCreate + 24
15 UIKitCore                      0x2d7744 _UIGraphicsBeginImageContextWithOptions + 204
16 Sentry                         0x66cdc -[SentryScreenshot takeScreenshots] + 56 (SentryScreenshot.m:56)
17 Sentry                         0x66a98 -[SentryScreenshot saveScreenShots:] + 31 (SentryScreenshot.m:31)
18 Sentry                         0x66e34 saveScreenShot + 16 (SentryScreenshotIntegration.m:16)
19 Sentry                         0x18fb8 onCrash + 105 (SentryCrashC.c:105)
20 Sentry                         0x242e0 sentrycrashcm_handleException + 235 (SentryCrashMonitor.c:235)
21 Sentry                         0x26314 handleSignal + 110 (SentryCrashMonitor_Signal.c:110)
22 libsystem_platform.dylib       0x2d48 _sigtramp + 52
23 libsystem_pthread.dylib        0xd844 pthread_kill + 208
24 libsystem_c.dylib              0x1f6ac abort + 124
25 libsystem_malloc.dylib         0x1b9d8 _malloc_put + 546
26 libsystem_malloc.dylib         0x1bc40 malloc_zone_error + 96
27 libsystem_malloc.dylib         0x1007c nanov2_allocate_from_block$VARIANT$mp + 544
28 libsystem_malloc.dylib         0xf280 nanov2_allocate$VARIANT$mp + 124
29 libsystem_malloc.dylib         0xf1b4 nanov2_malloc$VARIANT$mp + 60
30 libsystem_malloc.dylib         0x5efc _malloc_zone_malloc + 148
31 CoreGraphics                   0x250f0 ripc_GetRenderingState + 1224
32 CoreGraphics                   0x52168 ripc_DrawRects + 132
33 CoreGraphics                   0x1fcf4 CGContextFillRects + 116
34 CoreGraphics                   0x4b908 CGContextFillRect + 136
35 CoreGraphics                   0x4850c CGContextClearRect + 80
36 UIKitCore                      0x2d7770 _UIGraphicsBeginImageContextWithOptions + 248
37 Sentry                         0x66cdc -[SentryScreenshot takeScreenshots] + 56 (SentryScreenshot.m:56)
38 Sentry                         0x66a98 -[SentryScreenshot saveScreenShots:] + 31 (SentryScreenshot.m:31)
39 Sentry                         0x66e34 saveScreenShot + 16 (SentryScreenshotIntegration.m:16)
40 Sentry                         0x18fb8 onCrash + 105 (SentryCrashC.c:105)
41 Sentry                         0x242e0 sentrycrashcm_handleException + 235 (SentryCrashMonitor.c:235)
42 Sentry                         0x259b0 handleExceptions + 391 (SentryCrashMonitor_MachException.c:391)
43 libsystem_pthread.dylib        0x3338 _pthread_start + 116
44 libsystem_pthread.dylib        0x1938 thread_start + 8

The device information is :
Model:iPhone 7
Orientation:Portrait
RAM free: 59.39 MB
Disk free: 102.19 GB
Version:15.7.5
Orientation:Portrait
Jailbroken:No


The third one is
sentry::profiling::ThreadHandle::dispatchQueueAddress() co...
SIGSEGV

Crashed: io.sentry.SamplingProfiler
0  Sentry                         0x72514 sentry::profiling::ThreadHandle::dispatchQueueAddress() const + 141 (SentryThreadHandle.cpp:141)
1  Sentry                         0xdebc sentry::profiling::enumerateBacktracesForAllThreads(std::__1::function<void (sentry::profiling::Backtrace const&)> const&, std::__1::shared_ptr<sentry::profiling::ThreadMetadataCache> const&) + 164 (SentryBacktrace.cpp:164)
2  Sentry                         0x63188 sentry::profiling::(anonymous namespace)::samplingThreadMain(unsigned int, unsigned int, mach_timespec, std::__1::shared_ptr<sentry::profiling::ThreadMetadataCache>, std::__1::function<void (sentry::profiling::Backtrace const&)>, std::__1::atomic<unsigned long long>&, std::__1::function<void ()>) + 39 (SentrySamplingProfiler.cpp:39)
3  Sentry                         0x63740 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void* (*)(unsigned int, unsigned int, mach_timespec, std::__1::shared_ptr<sentry::profiling::ThreadMetadataCache>, std::__1::function<void (sentry::profiling::Backtrace const&)>, std::__1::atomic<unsigned long long>&, std::__1::function<void ()>), unsigned int, unsigned int, mach_timespec, std::__1::shared_ptr<sentry::profiling::ThreadMetadataCache>, std::__1::function<void (sentry::profiling::Backtrace const&)>, std::__1::reference_wrapper<std::__1::atomic<unsigned long long>>, std::__1::function<void ()>>>(void*) + 463 (function.h:463)
4  libsystem_pthread.dylib        0x3338 _pthread_start + 116
5  libsystem_pthread.dylib        0x1938 thread_start + 8

the device information is
Model:iPhone 7
Orientation:Portrait
RAM free: 33.83 MB
Disk free: 102.17 GB
Version:15.7.5
Orientation:Portrait
Jailbroken:No

Are you willing to submit a PR?

No response

@brustolin
Copy link
Contributor

Hello @Mohsenkhodadadzadehthelist thanks for the detailed information we will investigate numbers 1 and 3 and get back to you.

Number 2 looks like that the app has already crashed, and the screenshot failed. The screenshot process is a "Best effort" approach, but since the app is already in a crash state, its behavior becomes unpredictable. Unfortunately, there is nothing else we can do to guarantee that a screenshot will be taken. Occasionally, it may fail, but we consider this tradeoff acceptable.

The only alternative to completely avoid encountering this issue again is to disable screenshots.

@philipphofmann
Copy link
Member

@brustolin, I think it would be great to add that info about screenshots to the docs https://docs.sentry.io/platforms/apple/guides/ios/enriching-events/screenshots/.

@armcknight
Copy link
Member

armcknight commented May 22, 2023

Hi @Mohsenkhodadadzadehthelist , thanks for the report and information! We believe we fixed 1 in the 8.7.2 release. I'll take a look at 3 with @brustolin .

@armcknight
Copy link
Member

@Mohsenkhodadadzadehthelist that third crash has a message that is truncated:

sentry::profiling::ThreadHandle::dispatchQueueAddress() co...

Any chance you can grab the full contents of that entry?

@armcknight
Copy link
Member

@Mohsenkhodadadzadehthelist we are also wondering what the impact is of the third crash for you, if you could share any numbers on that. We actually have seen this crash in the past, but made a small change we thought would help, but it appears in some cases it still is problematic. We are also considering other solutions for it, and even removing the queue label collection entirely as so far it has been of limited value.

Any additional info we can get on this will help our decision making. Thanks again!

@kahest
Copy link
Member

kahest commented May 31, 2023

Hey @Mohsenkhodadadzadehthelist we recently released a couple of fixes that could be related to this issue, did you have a chance to update and test? Please let us know if the problem persists.

@kahest kahest closed this as not planned Won't fix, can't repro, duplicate, stale May 31, 2023
@github-project-automation github-project-automation bot moved this from Needs Investigation to Done in Mobile & Cross Platform SDK May 31, 2023
@SMzig
Copy link

SMzig commented Oct 28, 2024

I'm facing same issue in SDK version 8.38.0 any work around or solution?

@kahest
Copy link
Member

kahest commented Oct 28, 2024

@SMzig do you have more information, like the stack traces, is it the same as above? Do you have links to issues on sentry.io?

@SMzig
Copy link

SMzig commented Oct 28, 2024

Hello @kahest Yes it is same here is stack trace. Please let me know if it is different then reported

Fatal Exception: NSMallocException
0 CoreFoundation 0x83f20 __exceptionPreprocess
1 libobjc.A.dylib 0x172b8 objc_exception_throw
2 CoreFoundation 0x1b8af8 -[NSInvocation _initWithMethodSignature:frame:buffer:size:].cold.1
3 CoreFoundation 0x1b3bb8 __CFReallocationFailed
4 CoreFoundation 0x7dddc __CFSafelyReallocate
5 Foundation 0x3e3d0 _convertJSONString
6 Foundation 0x3e224 _writeJSONString
7 Foundation 0x3de78 ___writeJSONObject_block_invoke
8 CoreFoundation 0x24e54 NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK
9 CoreFoundation 0x24c98 -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:]
10 Foundation 0x3ec08 _writeJSONObject
11 Foundation 0x3dd8c ___writeJSONArray_block_invoke
12 CoreFoundation 0x24b14 NSARRAY_IS_CALLING_OUT_TO_A_BLOCK
13 CoreFoundation 0x24984 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:]
14 Foundation 0x3f544 _writeJSONArray
15 Foundation 0x3df68 ___writeJSONObject_block_invoke
16 CoreFoundation 0x24e54 NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK
17 CoreFoundation 0x24c98 -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:]
18 Foundation 0x3ec08 _writeJSONObject
19 Foundation 0x3df68 ___writeJSONObject_block_invoke
20 CoreFoundation 0x24e54 NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK
21 CoreFoundation 0x24c98 -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:]
22 Foundation 0x3ec08 _writeJSONObject
23 Foundation 0x20288 -[_NSJSONWriter dataWithRootObject:options:]
24 Foundation 0x20114 +[NSJSONSerialization dataWithJSONObject:options:error:]
25 Sentry 0x7bbf4 (Missing UUID 157001ddce163eefa20d03814df78f62)
26 Sentry 0x6dd68 (Missing UUID 157001ddce163eefa20d03814df78f62)
27 Sentry 0x9045c (Missing UUID 157001ddce163eefa20d03814df78f62)
28 Sentry 0x9011c (Missing UUID 157001ddce163eefa20d03814df78f62)
29 Sentry 0x8dac0 (Missing UUID 157001ddce163eefa20d03814df78f62)
30 libdispatch.dylib 0x3dd4 _dispatch_client_callout
31 libdispatch.dylib 0x786c _dispatch_block_invoke_direct
32 Sentry 0x40d44 (Missing UUID 157001ddce163eefa20d03814df78f62)
33 libdispatch.dylib 0x3dd4 _dispatch_client_callout
34 libdispatch.dylib 0x72d8 _dispatch_continuation_pop
35 libdispatch.dylib 0x1b1c8 _dispatch_source_latch_and_call
36 libdispatch.dylib 0x19d8c _dispatch_source_invoke
37 libdispatch.dylib 0xb284 _dispatch_lane_serial_drain
38 libdispatch.dylib 0xbf30 _dispatch_lane_invoke
39 libdispatch.dylib 0x16cb4 _dispatch_root_queue_drain_deferred_wlh
40 libdispatch.dylib 0x16528 _dispatch_workloop_worker_thread
41 libsystem_pthread.dylib 0x4934 _pthread_wqthread
42 libsystem_pthread.dylib 0x10cc start_wqthread

@kahest
Copy link
Member

kahest commented Oct 28, 2024

@SMzig the stack trace is slightly different, but it's possible it has a similar root cause. If you can get a stack trace with complete info on the Sentry frames (or a link to the issue on sentry.io - you can send it to [email protected] if you prefer) it would be appreciated if you create a new issue and refer to this one.

@philipphofmann
Copy link
Member

@SMzig, I think this is related to #4424. If it is, it could be that you're passing too large strings to the SentryScope, especially the extra of the scope. To fix this, you could reduce the length of the strings you're passing. We plan on truncating the strings so the SDK doesn't crash if somebody accidentally passes in huge strings.

@SMzig
Copy link

SMzig commented Oct 29, 2024

@philipphofmann thanks for reply,
possible it would be issue with size but I'm not logging anything manually. We are only using auto log service.

@SMzig
Copy link

SMzig commented Oct 29, 2024

@kahest I only have that stack trace for now, but I'll send you more details if I find them. Currently few user faced this issue I'm trying to figure out root cause. Here is configuration which I used to start sentry and it will be execute on launch

SentrySDK.start { options in
                options.dsn = ""
                options.environment = "production"
                options.debug = false
                options.tracesSampleRate = 1.0
                options.profilesSampleRate = 1.0
                options.enableAutoSessionTracking = true
                options.sessionTrackingIntervalMillis = 6000
            }

@philipphofmann
Copy link
Member

philipphofmann commented Oct 29, 2024

@SMzig, thanks for the update. We're currently validating if our SDK is doing too much work when apps are under high memory pressure that could cause these crashes. Please follow #4424 for updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

6 participants