Alamofire crashes only when running archived app

Created on 21 Oct 2016  路  10Comments  路  Source: Alamofire/Alamofire

I am having an issue with my HTTP request using Alamofire. When I try to reproduce the issue with the XCode debugger it does not crashes but when I archive the app and run the .ipa file on my iPad with ios 10.0.2 I always get a crash.

This is an example of a call that crashes when running the arhived app:

#static func loginOnServerUrl(serverURL: String, user: String, password: String,
        successCallback: ((JSON) -> Void)? = nil, failureCallback: ((Error) -> Void)? = nil){

            let params = [
                ApiParams.ACTION : "login",
                ApiParams.LoginParams.USER : user,
                ApiParams.LoginParams.PASSWORD : password,
            ]

        Alamofire.request("http://\(serverURL)/AppSrv", method: .get, parameters: params).responseJSON { response in
                switch response.result {
                case .success(let value):
                    //JSON raiz
                    let json = JSON(value)

                    for (key, value) in json.acceptingSigleValueAsArray {
                        log("\(key) : \(value)")
                    }


                     if let successCallback = successCallback {
                         successCallback(json)
                     }


                case .failure(let error):
                    log(error.localizedDescription)
                    if let failureCallback = failureCallback {
                        failureCallback(error)
                    }
                }
            }
    }

This is one of the crash logs I am getting:

Incident Identifier: ****
CrashReporter Key:   *****
Hardware Model:      iPad5,2
Process:             ****
Path:                ****
Identifier:         ****
Version:             1.42 (1.2.3a)
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           ****


Date/Time:           2016-10-21 10:16:08.9811 +0200
Launch Time:         2016-10-21 10:16:06.2504 +0200
OS Version:          iPhone OS 10.0.2 (14A456)
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x000000059480bec8
Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [0]
Triggered by Thread:  0

Filtered syslog:
None found

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libswiftCore.dylib              0x0000000100e19b6c 0x100c38000 + 1973100
1   myapp                           0x00000001000c4d88 static ServerManager.(pingOnServerUrl(serverUrl : String, successCallback : (Int64) -> ()?, failureCallback : (Error) -> ()?) -> ()).(closure #1) (ServerManager.swift:0)
2   Alamofire                       0x00000001003aca84 specialized DataRequest.(response<A where ...> (queue : DispatchQueue?, responseSerializer : A, completionHandler : (DataResponse<A.SerializedObject>) -> ()) -> Self).(closure #1).(closure #1) (ResponseSerialization.swift:0)
3   libdispatch.dylib               0x00000001889f1200 _dispatch_call_block_and_release + 24
4   libdispatch.dylib               0x00000001889f11c0 _dispatch_client_callout + 16
5   libdispatch.dylib               0x00000001889f5d6c _dispatch_main_queue_callback_4CF + 1000
6   CoreFoundation                  0x0000000189b15f2c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
7   CoreFoundation                  0x0000000189b13b18 __CFRunLoopRun + 1660
8   CoreFoundation                  0x0000000189a42048 CFRunLoopRunSpecific + 444
9   GraphicsServices                0x000000018b4c5198 GSEventRunModal + 180
10  UIKit                           0x000000018fa15628 -[UIApplication _run] + 684
11  UIKit                           0x000000018fa10360 UIApplicationMain + 208
12  myapp                           0x00000001000bf024 main (AppDelegate.swift:16)
13  libdyld.dylib                   0x0000000188a245b8 start + 4

Thread 1:
0   libsystem_kernel.dylib          0x0000000188b36a88 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x0000000188bf936c _pthread_wqthread + 1452
2   libsystem_pthread.dylib         0x0000000188bf8db4 start_wqthread + 4

Thread 2:
0   libsystem_kernel.dylib          0x0000000188b36a88 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x0000000188bf936c _pthread_wqthread + 1452
2   libsystem_pthread.dylib         0x0000000188bf8db4 start_wqthread + 4

Thread 3:
0   libsystem_pthread.dylib         0x0000000188bf8db0 start_wqthread + 0

Thread 4:
0   libsystem_pthread.dylib         0x0000000188bf8db0 start_wqthread + 0

Thread 5:
0   libsystem_kernel.dylib          0x0000000188b36a88 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x0000000188bf936c _pthread_wqthread + 1452
2   libsystem_pthread.dylib         0x0000000188bf8db4 start_wqthread + 4

Thread 6 name:  com.apple.uikit.eventfetch-thread
Thread 6:
0   libsystem_kernel.dylib          0x0000000188b1816c mach_msg_trap + 8
1   libsystem_kernel.dylib          0x0000000188b17fdc mach_msg + 72
2   CoreFoundation                  0x0000000189b15cec __CFRunLoopServiceMachPort + 192
3   CoreFoundation                  0x0000000189b13908 __CFRunLoopRun + 1132
4   CoreFoundation                  0x0000000189a42048 CFRunLoopRunSpecific + 444
5   Foundation                      0x000000018a550b1c -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 304
6   Foundation                      0x000000018a57160c -[NSRunLoop(NSRunLoop) runUntilDate:] + 96
7   UIKit                           0x000000019038ac7c -[UIEventFetcher threadMain] + 136
8   Foundation                      0x000000018a64e50c __NSThread__start__ + 1024
9   libsystem_pthread.dylib         0x0000000188bfb860 _pthread_body + 240
10  libsystem_pthread.dylib         0x0000000188bfb770 _pthread_body + 0
11  libsystem_pthread.dylib         0x0000000188bf8dbc thread_start + 4

Thread 7 name:  com.apple.NSURLConnectionLoader
Thread 7:
0   libsystem_kernel.dylib          0x0000000188b1816c mach_msg_trap + 8
1   libsystem_kernel.dylib          0x0000000188b17fdc mach_msg + 72
2   CoreFoundation                  0x0000000189b15cec __CFRunLoopServiceMachPort + 192
3   CoreFoundation                  0x0000000189b13908 __CFRunLoopRun + 1132
4   CoreFoundation                  0x0000000189a42048 CFRunLoopRunSpecific + 444
5   CFNetwork                       0x000000018a22fcec +[NSURLConnection(Loader) _resourceLoadLoop:] + 336
6   Foundation                      0x000000018a64e50c __NSThread__start__ + 1024
7   libsystem_pthread.dylib         0x0000000188bfb860 _pthread_body + 240
8   libsystem_pthread.dylib         0x0000000188bfb770 _pthread_body + 0
9   libsystem_pthread.dylib         0x0000000188bf8dbc thread_start + 4

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000170246c30   x1: 0x0000000170246c30   x2: 0x0000000000000008   x3: 0x0000000188b7c250
    x4: 0x0000000100e099a4   x5: 0x0000000100df14f8   x6: 0x0000000000000065   x7: 0x0000000170287c78
    x8: 0x000000059480bea8   x9: 0x0000000ffffffff8  x10: 0x0000000000000001  x11: 0xbaddc0dedeadbead
   x12: 0x0000000000000177  x13: 0x0000000000000177  x14: 0x0000000100be6a30  x15: 0x0000000000000000
   x16: 0x0000000100e19b54  x17: 0xb000000000000003  x18: 0x0000000000000000  x19: 0x0000000000000000
   x20: 0x0000000100e94060  x21: 0x00000001ae195ef8  x22: 0x000000017046cf40  x23: 0xb000000000000003
   x24: 0x0000000000000000  x25: 0x0000000000000000  x26: 0x0000000000000004  x27: 0x0000000100be6a30
   x28: 0x0000000170246c30   fp: 0x000000016fd46b60   lr: 0x00000001000c4d88
    sp: 0x000000016fd46870   pc: 0x0000000100e19b6c cpsr: 0x20000000
needs feedback

Most helpful comment

We are experiencing this issue too, in Objective-C project. Changing Optimization Level didn't worked for us.

All 10 comments

I am getting EXC_BAD_ACCESS(code=1, address=...) in ResponseSerialization.swift (line 159)

(queue ?? DispatchQueue.main).async { completionHandler(dataResponse) }

By default, frameworks integrated using CocoaPods get an optimization level of -O, whereas Swift apps now default to -O -whole-module-optimization. Perhaps this mismatch is causing issue? I make all of my pods have whole module optimization by using this post install hook:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      if config.name != 'Debug'
        config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Owholemodule'
      else
        config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Onone'
      end
    end
  end
end

Let us know if this fixes the issue for you.

Finally was same of https://github.com/Alamofire/Alamofire/issues/1637
I solved it by setting the Release optimization level to same as the main target (Fast, Single-File Optimization)

Hi @adrimarti I think I have the same issue. Where do you set the Release optimization level? Thanks

Hi @Tindi

Inside XCode>project settings>Build Settings. Try to find the keyword 'optimization'.
Then change the value for key 'Optimization Level'>'Release'. You have to put the same level in your project target and in the module Alamofire.

For testing that it works correctly run your app with 'Release' scheme (same as when it is uploaded to AppStore).

upload

I am experiencing the same issue but only with a really small % of my app users. Tested setting the optimizatiob level to the same as main target to Fast, Single-File and Whole module optimization without any success. Any other workaround?

Hi @adrimarti seems to be working for me. Thanks!

We are experiencing this issue too, in Objective-C project. Changing Optimization Level didn't worked for us.

This did not work for us either.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Tulleb picture Tulleb  路  3Comments

yokesharun picture yokesharun  路  3Comments

hengchengfei picture hengchengfei  路  3Comments

tib picture tib  路  3Comments

zhouhao27 picture zhouhao27  路  3Comments