7

I just upgraded one of my apps to Swift 5, I didn't change so much at all and there didn't seem to be any problems, so I just released it in production (fortunately in phased release). After 1 days I started to see a very strange crash on Crashlytics that affect the 15% of people that is using my app.

This is the stack trace:

Crashed: com.apple.main-thread
0  (Missing)                      0x31698aa1503e0 (Missing)
1  libswiftCore.dylib             0x1afa5ac68 _swift_release_dealloc + 28
2  App                            0x104194c3c outlined consume of MyModel? + 4300033084
3  App                            0x104482cb8 @objc MyController.__ivar_destroyer (<compiler-generated>)
4  libobjc.A.dylib                0x180f267cc object_cxxDestructFromClass(objc_object*, objc_class*) + 148
5  libobjc.A.dylib                0x180f366b8 objc_destructInstance + 68
6  libobjc.A.dylib                0x180f36720 object_dispose + 16
7  UIKitCore                      0x1ae2edac0 -[UIResponder dealloc] + 152
8  UIKitCore                      0x1add173e0 -[UIViewController dealloc] + 1748
9  App                            0x10431d82c BaseViewController.__deallocating_deinit (MyController.swift:56)
10 App                            0x10431d85c @objc BaseViewController.__deallocating_deinit (<compiler-generated>)
11 libobjc.A.dylib                0x180f41b9c (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 672
12 CoreFoundation                 0x181d59f40 _CFAutoreleasePoolPop + 28
13 CoreFoundation                 0x181cd8e00 __CFRunLoopRun + 1932
14 CoreFoundation                 0x181cd8354 CFRunLoopRunSpecific + 436
15 GraphicsServices               0x183ed879c GSEventRunModal + 104
16 UIKitCore                      0x1ae2c3b68 UIApplicationMain + 212
17 App                            0x104108468 main (AppDelegate.swift:21)
18 libdyld.dylib                  0x18179e8e0 start + 4

I searched already something on the web but I find only a thread on the Swift Forum not very related to this.

MyModel is actually a struct model that is nested into another Model. MyController is the very huge controller that manages the model.

The crash seems to happen obviously when popping the controller and so when the System tries to deallocate all the related properties.

I tried to replicate it many times with no results, and I didn't know really where to start looking.

Someone had the same problem?

UPDATE [Partially Fixed]: It seemed to be a stack corruption caused by a Advertising Framework, to fix this I moved MyModel from Struct to Class, it's now on the Heap and can't get double freed.

iDevid
  • 507
  • 3
  • 13
  • Please provide more information. We have no idea how your VC manipulates this model. As for Crashlytics, it loves to group related issues but sometimes it gets it horribly wrong and leads you towards a rabbit chase of something completely unrelated. – Jacob Apr 27 '19 at 00:22

1 Answers1

8

From my experience, most of the outlined consume of errors are caused by concurrency issue. When one queue/thread reading the struct while another queue/thread modifying it without synchronization (mutex, semaphore, barrier, etc).

You need to check all threads stacks to see which thread access MyModel simultaneously with the Main(crashed) thread.

Jurasic
  • 1,845
  • 1
  • 23
  • 29