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

Crash SEGFileStorage.m - Analytics v4.0.4 #936

Closed
vpetrosky opened this issue Aug 24, 2020 · 4 comments
Closed

Crash SEGFileStorage.m - Analytics v4.0.4 #936

vpetrosky opened this issue Aug 24, 2020 · 4 comments

Comments

@vpetrosky
Copy link

Since updating to Analytics version 4.0.4, we have a new trending crash.

An exception is thrown on app start up, when we fire our first few Segment events. It's reported in Firebase as a fatal crash. In my testing, I've been able to hit an exception breakpoint but am able to continue with program execution when debugging. I worry though, that this exception may sometimes result in a fatal crash that's affecting users.

Details
Operating Systems: 100% iOS 13
Device States: 75% background

Invalid type in JSON write (__NSTaggedDate)

-[SEGFileStorage dataFromJSON:]
Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x1b57c5654 __exceptionPreprocess
1  libobjc.A.dylib                0x1b54e7bcc objc_exception_throw
2  Foundation                     0x1b5c3db7c _writeJSONValue
3  Foundation                     0x1b5c404a0 ___writeJSONObject_block_invoke
4  CoreFoundation                 0x1b5812c14 __NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK__
5  CoreFoundation                 0x1b569efc4 -[__NSFrozenDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:]
6  Foundation                     0x1b5c3f9d0 _writeJSONObject
7  Foundation                     0x1b5c404a0 ___writeJSONObject_block_invoke
8  CoreFoundation                 0x1b5812c14 __NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK__
9  CoreFoundation                 0x1b569efc4 -[__NSFrozenDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:]
10 Foundation                     0x1b5c3f9d0 _writeJSONObject
11 Foundation                     0x1b5c404a0 ___writeJSONObject_block_invoke
12 CoreFoundation                 0x1b5812c14 __NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK__
13 CoreFoundation                 0x1b569efc4 -[__NSFrozenDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:]
14 Foundation                     0x1b5c3f9d0 _writeJSONObject
15 Foundation                     0x1b5c407a8 ___writeJSONArray_block_invoke
16 CoreFoundation                 0x1b5798ce0 __NSARRAY_IS_CALLING_OUT_TO_A_BLOCK__
17 CoreFoundation                 0x1b569d70c -[__NSArrayI enumerateObjectsWithOptions:usingBlock:]
18 Foundation                     0x1b5c3fe7c _writeJSONArray
19 Foundation                     0x1b5af500c -[_NSJSONWriter dataWithRootObject:options:error:]
20 Foundation                     0x1b5af4c90 +[NSJSONSerialization dataWithJSONObject:options:error:]
21 Analytics                      0x1032ba0c8 -[SEGFileStorage dataFromJSON:] + 198 (SEGFileStorage.m:198)
22 Analytics                      0x1032ba008 -[SEGFileStorage setJSON:forKey:] + 187 (SEGFileStorage.m:187)
23 Analytics                      0x1032b9afc -[SEGFileStorage setArray:forKey:] + 107 (SEGFileStorage.m:107)
24 Analytics                      0x1032c4678 -[SEGSegmentIntegration persistQueue] + 499 (SEGSegmentIntegration.m:499)
25 Analytics                      0x1032c4158 __34-[SEGSegmentIntegration sendData:]_block_invoke_2 + 414 (SEGSegmentIntegration.m:414)
26 Analytics                      0x1032c97bc __seg_dispatch_specific_block_invoke + 465 (SEGUtils.m:465)
27 libdispatch.dylib              0x1b548a9a8 _dispatch_call_block_and_release
28 libdispatch.dylib              0x1b548b524 _dispatch_client_callout
29 libdispatch.dylib              0x1b54378a4 _dispatch_lane_serial_drain$VARIANT$mp
30 libdispatch.dylib              0x1b5438294 _dispatch_lane_invoke$VARIANT$mp
31 libdispatch.dylib              0x1b544178c _dispatch_workloop_worker_thread
32 libsystem_pthread.dylib        0x1b54dcb74 _pthread_wqthread
33 libsystem_pthread.dylib        0x1b54df740 start_wqthread

When I set an exception breakpoint, Xcode displays the following error and this stack trace in the debug navigator:
Thread 4: Exception: "Invalid type in JSON write (__NSTaggedDate)"

Thread 4 Queue : io.segment.analytics.segmentio (serial)
#0	0x00007fff208e6982 in objc_exception_throw ()
#19	0x0000000110f6c3fa in +[NSJSONSerialization dataWithJSONObject:options:error:] ()
#20	0x000000010e86f5b9 in -[SEGFileStorage dataFromJSON:] at /.../Pods/Analytics/Analytics/Internal/SEGFileStorage.m:198
#21	0x000000010e86f490 in -[SEGFileStorage setJSON:forKey:] at /.../Pods/Analytics/Analytics/Internal/SEGFileStorage.m:187
#22	0x000000010e86ed5d in -[SEGFileStorage setArray:forKey:] at /.../Pods/Analytics/Analytics/Internal/SEGFileStorage.m:107
#23	0x000000010e881022 in -[SEGSegmentIntegration persistQueue] at /.../Pods/Analytics/Analytics/Classes/SEGSegmentIntegration.m:499
#24	0x000000010e87f77b in -[SEGSegmentIntegration queuePayload:] at /.../Pods/Analytics/Analytics/Classes/SEGSegmentIntegration.m:314
#25	0x000000010e87f42c in __71-[SEGSegmentIntegration enqueueAction:dictionary:context:integrations:]_block_invoke at /.../Pods/Analytics/Analytics/Classes/SEGSegmentIntegration.m:304
#26	0x000000010e889c21 in __seg_dispatch_specific_block_invoke at /.../Pods/Analytics/Analytics/Internal/SEGUtils.m:464
#27	0x000000011992cf11 in _dispatch_call_block_and_release ()
#33	0x00007fff2151bb77 in start_wqthread ()

This may or may not be related to issues described here: #929

@migs647
Copy link
Contributor

migs647 commented Aug 24, 2020

Thanks for reporting this @vpetrosky, we're looking into it.

@bsneed
Copy link
Contributor

bsneed commented Aug 24, 2020

@vpetrosky this is NSJSONSerialization telling you that you have a type trying to go out in one of your events that is not serializable.

Exception: "Invalid type in JSON write (__NSTaggedDate)

We check for conformance to NSCoding, ideally so the error shows higher up in the chain and makes it easier to debug with more context (ie: the actual key being worked with) and it looks like this is making it past that check. NSTaggedDate is an Apple internal type so it could have something to do with what on the surface appears to be an NSDate but is actually NSTaggedDate underneath. If you find out how the NSDate is being created on your end to produce the NSTaggedDate type, we can probably make a patch. We'll look here as well and see if we can determine what it is as well.

@vpetrosky
Copy link
Author

@bsneed Thanks for the response! I think I've found the call that's triggering the exception. I'm initializing a Swift date and passing it as a value in the traits dictionary when calling identify.

let properties = ["key": Date()]
identifyUser(userId, properties: properties)

Is Date no longer an allowable type? Is this a recent change?

@bsneed
Copy link
Contributor

bsneed commented Aug 25, 2020

Hi @vpetrosky! Not sure it was ever an allowed type as dates can’t be serialized, BUT what we’re trying to do is give developers better info on things like this. So it may have just gotten dropped before. You’ll need to convert it to a string before adding it. The fix noted above narrows the allowable scope and should be an early warning for next time. 🙏

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

No branches or pull requests

3 participants