CFNetwork crash on iOS 13

We get a crash in CFNetwork for some iPhone7 and iPhone XR devices in BetaTestFlight. We have submitted the app to Beta but for some devices it gets a crash. In code the crash happens when creating a URL ( let url: URL = URL(string: urlString)! ) I know the forced unwrapping is the one that creates the crash but it only happens in some devices. In most of the devices it run completely right. Here i post the crash threads.


OS Version: iPhone OS 13.1.3 (17A878)
Release Type: User
Baseband Version:2.01.08
Report Version: 104


Exception Type: EXC_BREAKPOINT (SIGTRAP)

Exception Codes: 0x0000000000000001, 0x0000000104be4808

Termination Signal: Trace/BPT trap: 5

Termination Reason: Namespace SIGNAL, Code 0x5

Terminating Process: exc handler [563]

Triggered by Thread: 6


Thread 0 name:

Thread 0:

0 libsystem_kernel.dylib 0x00000001b85febc4 mach_msg_trap + 8

1 libsystem_kernel.dylib 0x00000001b85fdfe0 mach_msg + 76 (mach_msg.c:103)

2 CoreFoundation 0x00000001b87b0abc __CFRunLoopServiceMachPort + 220 (CFRunLoop.c:2575)

3 CoreFoundation 0x00000001b87ab954 __CFRunLoopRun + 1428 (CFRunLoop.c:2931)

4 CoreFoundation 0x00000001b87ab098 CFRunLoopRunSpecific + 480 (CFRunLoop.c:3192)

5 GraphicsServices 0x00000001c2915534 GSEventRunModal + 108 (GSEvent.c:2246)

6 UIKitCore 0x00000001bc8cb7ac UIApplicationMain + 1940 (UIApplication.m:4753)

7 ProjectName 0x0000000104bc2c84 main + 68 (DetailViewController.swift:12)

8 libdyld.dylib 0x00000001b862af30 start + 4


Thread 1 name:

Thread 1:

0 libsystem_kernel.dylib 0x00000001b85febc4 mach_msg_trap + 8

1 libsystem_kernel.dylib 0x00000001b85fdfe0 mach_msg + 76 (mach_msg.c:103)

2 CoreFoundation 0x00000001b87b0abc __CFRunLoopServiceMachPort + 220 (CFRunLoop.c:2575)

3 CoreFoundation 0x00000001b87ab954 __CFRunLoopRun + 1428 (CFRunLoop.c:2931)

4 CoreFoundation 0x00000001b87ab098 CFRunLoopRunSpecific + 480 (CFRunLoop.c:3192)

5 Foundation 0x00000001b8af0580 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 232 (NSRunLoop.m:374)

6 Foundation 0x00000001b8af0458 -[NSRunLoop(NSRunLoop) runUntilDate:] + 92 (NSRunLoop.m:421)

7 UIKitCore 0x00000001bc966668 -[UIEventFetcher threadMain] + 156 (UIEventFetcher.m:637)

8 Foundation 0x00000001b8aef1e4 -[NSThread main] + 40 (NSThread.m:760)

9 Foundation 0x00000001b8c2aa84 __NSThread__start__ + 852 (NSThread.m:724)

10 libsystem_pthread.dylib 0x00000001b8540d5c _pthread_start + 128 (pthread.c:895)

11 libsystem_pthread.dylib 0x00000001b8548c84 thread_start + 8


Thread 2:

0 libsystem_pthread.dylib 0x00000001b8548c70 start_wqthread + 0


Thread 3 name:

Thread 3:

0 libsystem_kernel.dylib 0x00000001b85febc4 mach_msg_trap + 8

1 libsystem_kernel.dylib 0x00000001b85fdfe0 mach_msg + 76 (mach_msg.c:103)

2 CoreFoundation 0x00000001b87b0abc __CFRunLoopServiceMachPort + 220 (CFRunLoop.c:2575)

3 CoreFoundation 0x00000001b87ab954 __CFRunLoopRun + 1428 (CFRunLoop.c:2931)

4 CoreFoundation 0x00000001b87ab098 CFRunLoopRunSpecific + 480 (CFRunLoop.c:3192)

5 CFNetwork 0x00000001bba6dbc8 -[__CoreSchedulingSetRunnable runForever] + 192 (CoreSchedulingSet.mm:1372)

6 Foundation 0x00000001b8aef1e4 -[NSThread main] + 40 (NSThread.m:760)

7 Foundation 0x00000001b8c2aa84 __NSThread__start__ + 852 (NSThread.m:724)

8 libsystem_pthread.dylib 0x00000001b8540d5c _pthread_start + 128 (pthread.c:895)

9 libsystem_pthread.dylib 0x00000001b8548c84 thread_start + 8


Thread 4:

0 libsystem_pthread.dylib 0x00000001b8548c70 start_wqthread + 0


Thread 5:

0 libsystem_pthread.dylib 0x00000001b8548c70 start_wqthread + 0


Thread 6 name:

Thread 6 Crashed:

0 ProjectName 0x0000000104be4808 closure #1 in ViewController.request() + 2848 (ViewController.swift:196)

1 ProjectName 0x0000000104bf558c thunk for @escaping @callee_guaranteed (@guaranteed Data?, @guaranteed NSURLResponse?, @guarantee... + 148 (<compiler-generated>:0)

2 CFNetwork 0x00000001bba92ffc __40-[__NSURLSessionLocal taskForClassInfo:]_block_invoke + 40 (LocalSession.mm:713)

3 CFNetwork 0x00000001bbaa38dc __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 224 (LocalSessionTask.mm:566)

4 Foundation 0x00000001b8c05c60 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 24 (NSOperation.m:1541)

5 Foundation 0x00000001b8b077e8 -[NSBlockOperation main] + 104 (NSOperation.m:1560)

6 Foundation 0x00000001b8c07fbc __NSOPERATION_IS_INVOKING_MAIN__ + 24 (NSOperation.m:2184)

7 Foundation 0x00000001b8b07464 -[NSOperation start] + 740 (NSOperation.m:2201)

8 Foundation 0x00000001b8c089e8 __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__ + 24 (NSOperation.m:2215)

9 Foundation 0x00000001b8c084a8 __NSOQSchedule_f + 184 (NSOperation.m:2226)

10 libdispatch.dylib 0x00000001b84e93ac _dispatch_block_async_invoke2 + 144 (queue.c:522)

11 libdispatch.dylib 0x00000001b84dd00c _dispatch_client_callout + 20 (object.m:495)

12 libdispatch.dylib 0x00000001b84df78c _dispatch_continuation_pop + 408 (inline_internal.h:2487)

13 libdispatch.dylib 0x00000001b84deeec _dispatch_async_redirect_invoke + 596 (queue.c:800)

14 libdispatch.dylib 0x00000001b84ebbd4 _dispatch_root_queue_drain + 348 (inline_internal.h:2528)

15 libdispatch.dylib 0x00000001b84ec384 _dispatch_worker_thread2 + 120 (queue.c:6569)

16 libsystem_pthread.dylib 0x00000001b8542a60 _pthread_wqthread + 216 (pthread.c:2336)

17 libsystem_pthread.dylib 0x00000001b8548c78 start_wqthread + 8


Thread 7:

0 libsystem_pthread.dylib 0x00000001b8548c70 start_wqthread + 0


Thread 6 crashed with ARM Thread State (64-bit):

x0: 0x0000000000000001 x1: 0x000000007fffffff x2: 0x00000001fdd02338 x3: 0x0000000000000003

x4: 0x00000001f7b5eae8 x5: 0x0000000000000020 x6: 0x326664326d386163 x7: 0x0000000000000000

x8: 0x0000000000000000 x9: 0x00000000ffffffff x10: 0x000000000073f800 x11: 0x0000000000bf3d01

x12: 0x0000000108080000 x13: 0x0000000000004009 x14: 0x000000010807c000 x15: 0x0000000000003fff

x16: 0x00000001b852964c x17: 0x00000001b852964c x18: 0x0000000000000000 x19: 0x00000001080bc800

x20: 0x000000016b3eaa50 x21: 0xc000000000000015 x22: 0x00000001f7b6bbc8 x23: 0xc000000000000015

x24: 0x00000001fdd02338 x25: 0x000000010686c400 x26: 0x40000002825f43c0 x27: 0x40000002825f42d0

x28: 0x00000001f7b5eae8 fp: 0x000000016b3eab50 lr: 0x0000000104be4634

sp: 0x000000016b3eaa30 pc: 0x0000000104be4808 cpsr: 0x60000000

esr: 0xf2000001 Address size fault

Replies

It looks like Thread 6 is causing the crash:


0 ProjectName 0x0000000104be4808 closure #1 in ViewController.request() + 2848 (ViewController.swift:196)

1 ProjectName 0x0000000104bf558c thunk for @escaping @callee_guaranteed (@guaranteed Data?, @guaranteed NSURLResponse?, @guarantee... + 148 (<compiler-generated>:0)


What is happening on line 196 of ViewController.request()?

Is this the completion handler for NSURLSession?

Hello,


Did you ever resolve this issue? I am getting an almost identical crash report, again for a very small number of users.


Thanks,


Paul