Alamofire: EXC_BAD_ACCESS (code=EXC_I386_GPFLT) on authenticate() method

Created on 7 Apr 2020  Â·  20Comments  Â·  Source: Alamofire/Alamofire

ℹ Please fill out this template when filing an issue.
All lines beginning with an ℹ symbol instruct you with what info we expect. You can delete those lines once you've filled in the info.

Per our *CONTRIBUTING guidelines, we use GitHub for
bugs and feature requests, not general support. Other issues should be opened on Stack Overflow with the tag alamofire.

Please remove this line and everything above it before submitting.

What did you do?

ℹ Upgraded to latest 5.1.0 version and then threw a EXC_BAD_ACCESS error. I downgrade back to version 5.0.5 and now it is working.

Screen Shot 2020-04-07 at 10 09 02 AM

What did you expect to happen?

ℹ Should've work like the previous version

What happened instead?

ℹ threw a EXC_BAD_ACCESS error

Alamofire Environment

Alamofire version:5.1.0
*Xcode version:11.4*
*Swift version:5.2*
**Platform(s) running Alamofire:

macOS version running Xcode:

Demo Project

ℹ Please link to or upload a project we can download that reproduces the issue.

needs investigation

All 20 comments

It's difficult to investigate without at least a full stack trace from the crash. Even better if you have a project that can replicate the issue. But first, have you enabled library evolution mode?

@jshier
Below is the track trace

thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
  * frame #0: 0x000000010d49c954 Alamofire`outlined init with copy of Alamofire.CachedResponseHandler + 4
    frame #1: 0x000000010d47d5e1 Alamofire`closure #1 (inout Alamofire.Request.MutableState) -> () in Alamofire.Request.cacheResponse(using: Alamofire.CachedResponseHandler) -> Self + 369
    frame #2: 0x000000010d46fb5c Alamofire`reabstraction thunk helper from @callee_guaranteed (@inout Alamofire.Request.MutableState) -> () to @escaping @callee_guaranteed (@inout Alamofire.Request.MutableState) -> (@out ()) + 12
    frame #3: 0x000000010d47fd91 Alamofire`reabstraction thunk helper from @callee_guaranteed (@inout Alamofire.Request.MutableState) -> () to @escaping @callee_guaranteed (@inout Alamofire.Request.MutableState) -> (@out ())partial apply forwarder with unmangled suffix ".24" + 17
    frame #4: 0x000000010d468f92 Alamofire`closure #1 () -> A1 in Alamofire.Protector.write<A>((inout A) -> A1) -> A1 + 130
    frame #5: 0x000000010d468fd1 Alamofire`partial apply forwarder for closure #1 () -> A1 in Alamofire.Protector.write<A>((inout A) -> A1) -> A1 + 33
    frame #6: 0x000000010d4683ac Alamofire`Alamofire.UnfairLock.around<A>(() -> A) -> A + 76
    frame #7: 0x000000010d468eed Alamofire`Alamofire.Protector.write<A>((inout A) -> A1) -> A1 + 189
    frame #8: 0x000000010d47d443 Alamofire`Alamofire.Request.cacheResponse(using: Alamofire.CachedResponseHandler) -> Self + 131
    frame #9: 0x000000010ca8fb4b OnlineJobs.ph`MessagesViewController.devLogin(category=inbox, self=0x00007ff6eb0e7c70) at MessagesViewController.swift:56:14
    frame #10: 0x000000010ca8f09e OnlineJobs.ph`MessagesViewController.viewDidLoad(self=0x00007ff6eb0e7c70) at MessagesViewController.swift:34:9
    frame #11: 0x000000010ca8f11b OnlineJobs.ph`@objc MessagesViewController.viewDidLoad() at <compiler-generated>:0
    frame #12: 0x00007fff4856c066 UIKitCore`-[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 83
    frame #13: 0x00007fff48570f84 UIKitCore`-[UIViewController loadViewIfRequired] + 1084
    frame #14: 0x00007fff485713a1 UIKitCore`-[UIViewController view] + 27
    frame #15: 0x00007fff484a833b UIKitCore`-[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 591
    frame #16: 0x00007fff484a7828 UIKitCore`-[UITabBarController transitionFromViewController:toViewController:] + 59
    frame #17: 0x00007fff484a3cfb UIKitCore`-[UITabBarController _setSelectedViewController:] + 426
    frame #18: 0x00007fff484a3b17 UIKitCore`-[UITabBarController setSelectedViewController:] + 109
    frame #19: 0x00007fff484a777d UIKitCore`-[UITabBarController _tabBarItemClicked:] + 602
    frame #20: 0x00007fff48c1a4d5 UIKitCore`-[UIApplication sendAction:to:from:forEvent:] + 83
    frame #21: 0x00007fff482f0147 UIKitCore`-[UITabBar _sendAction:withEvent:] + 557
    frame #22: 0x00007fff48c1a4d5 UIKitCore`-[UIApplication sendAction:to:from:forEvent:] + 83
    frame #23: 0x00007fff485cbc83 UIKitCore`-[UIControl sendAction:to:forEvent:] + 223
    frame #24: 0x00007fff485cbfcb UIKitCore`-[UIControl _sendActionsForEvents:withEvent:] + 396
    frame #25: 0x00007fff482f2b7d UIKitCore`-[UITabBar _buttonUp:] + 113
    frame #26: 0x00007fff48c1a4d5 UIKitCore`-[UIApplication sendAction:to:from:forEvent:] + 83
    frame #27: 0x00007fff485cbc83 UIKitCore`-[UIControl sendAction:to:forEvent:] + 223
    frame #28: 0x00007fff485cbfcb UIKitCore`-[UIControl _sendActionsForEvents:withEvent:] + 396
    frame #29: 0x00007fff485caf3c UIKitCore`-[UIControl touchesEnded:withEvent:] + 497
    frame #30: 0x00007fff48c55d10 UIKitCore`-[UIWindow _sendTouchesForEvent:] + 1359
    frame #31: 0x00007fff48c57a95 UIKitCore`-[UIWindow sendEvent:] + 4501
    frame #32: 0x00007fff48c31ed9 UIKitCore`-[UIApplication sendEvent:] + 356
    frame #33: 0x00007fff48cbc336 UIKitCore`__dispatchPreprocessedEventFromEventQueue + 7328
    frame #34: 0x00007fff48cbf502 UIKitCore`__handleEventQueueInternal + 6565
    frame #35: 0x00007fff48cb606b UIKitCore`__handleHIDEventFetcherDrain + 88
    frame #36: 0x00007fff23da1c71 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    frame #37: 0x00007fff23da1b9c CoreFoundation`__CFRunLoopDoSource0 + 76
    frame #38: 0x00007fff23da1374 CoreFoundation`__CFRunLoopDoSources0 + 180
    frame #39: 0x00007fff23d9bf6e CoreFoundation`__CFRunLoopRun + 974
    frame #40: 0x00007fff23d9b884 CoreFoundation`CFRunLoopRunSpecific + 404
    frame #41: 0x00007fff38b5ac1a GraphicsServices`GSEventRunModal + 139
    frame #42: 0x00007fff48c19220 UIKitCore`UIApplicationMain + 1605
    frame #43: 0x000000010cacb39b OnlineJobs.ph`main at AppDelegate.swift:17:7
    frame #44: 0x00007fff519b910d libdyld.dylib`start + 1

Most likely you're attempting to call cacheResponse(using:) a second time on the same Request, though it doesn't quite match the stack you've posted. Nor does the screenshot you originally posted. Can you provide the Alamofire usage from your MessagesViewController.devLogin method? Also, can you confirm how you're integrating Alamofire and whether you've enabled library evolution mode?

Here's my usage

let parameters: Parameters = [
            "username": "[email protected]",
            "password": "password"
]
        AF.request("https://someurl.com", method: .post, parameters: parameters)
            .authenticate(username: "someusername", password: "password")
            .responseJSON { response in
        }

It will crash on authenticate() method. Inside this ViewController I will call 2-3 Alamofire requests and each request needs to call authenticate method, this is just a temporary for debugging on the backend. No I haven't done any library evolution mode.

Very odd. Your stack trace doesn’t match that usage. How are you integrating Alamofire?

I'm using Cocoapods.

Sorry, I can't reproduce this, even making very similar calls to what you show and upgrading between 5.0.5 and 5.1. Can you try deleting your Pods directory and doing the update again?

I meet the same question, when upgrade to 5.1.0, it crashes everytime and I had to downgrade it to 5.0.5.
Here is the track trace :
Crashed: com.apple.main-thread
0 libswiftCore.dylib 0x1023159f0 _swift_release_dealloc + 16
1 Alamofire 0x100bf1f2c CompositeEventMonitor.request(_:didCreateInitialURLRequest:) + 172
2 Alamofire 0x100bf1f2c CompositeEventMonitor.request(_:didCreateInitialURLRequest:) + 172
3 libswiftCore.dylib 0x1023159fc _swift_release_dealloc + 28
4 Alamofire 0x100bf37ac outlined init with copy of DownloadResponse + 2312 (:2312)
5 libswiftCore.dylib 0x1023159fc _swift_release_dealloc + 28
6 libsystem_blocks.dylib 0x18a1dfa68 _Block_release + 160
7 libdispatch.dylib 0x18a18a9a0 _dispatch_client_callout + 16
8 libdispatch.dylib 0x18a18f5e8 _dispatch_main_queue_callback_4CF + 996
9 CoreFoundation 0x18b2810c8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
10 CoreFoundation 0x18b27ece4 __CFRunLoopRun + 1572
11 CoreFoundation 0x18b1aeda4 CFRunLoopRunSpecific + 424
12 GraphicsServices 0x18cc18074 GSEventRunModal + 100
13 UIKit 0x191469058 UIApplicationMain + 208
14 libswiftUIKit.dylib 0x102aa5468 UIApplicationMain(_:_:_:_:) + 168
15 YoudaoK12 0x1001047fc main + 160516 (:160516)
16 libdyld.dylib 0x18a1bd59c start + 4

I got similar problem after updated to 5.1.0. But I use through Moya.

image

It's crashlytics crash record's snapshots.

Are any of you using precompiled binaries at all? Or are you running on 32-bit devices? I'd also recommend checking to see if the crashes occur when building with or without optimization. There seem to be a few Swift 5.2 bugs that can cause runtime crashes, especially on 32-bit devices.

Also, if anyone has an example project that replicates the issue, that'd be great to see.

In my case:
Xcode 11.4(Swift5.2)
Runtime crash occurs on 64 bit cpu ex) I confirmed iPhone7 and iPhone Xs.
Runtime crash occurs when building with optimization(Crashes occur only on Release build).

One case of Stack trace on Crashlytics:
image

Could anyone seeing crashes using Xcode 11.4 upgrade to Xcode 11.4.1 when they get a chance and try to replicate the issue?

I have the same issue as well.

Can everyone seeing issues do us a favor and compare Xcode versions? With the same code, try to replicate the issue using Xcode 11.3.1, Xcode 11.4.1, and the Xcode 11.5 beta. It would be great to narrow down whether this is a compiler issue or something more inherent to Alamofire. It seems like a compiler issue but a comparison will be great.

Hi @jshier we're also seeing crashes, including https://github.com/Alamofire/Alamofire/issues/3174, with builds from Testflight build with Xcode 11.4.x. We've reverted our stack to 11.3.1 and no crashes so far 🤞.

Hi! Encountering the same issue, unable to reproduce with "Release" compile mode using Xcode, but exact Release (Enterprise) builds are crashing in the following way (Xcode 11.4.1, iPhone 7, iOS 13.4.1, Alamofire 5.1.0, 5.2.0):
image
UPD: Looks like changing Xcode version to 11.3 and using latest Alamofire version (5.2.0) works.

I am also getting this issue.
Screenshot 2020-06-13 at 10 45 43 AM

Closing, as this looks like a Swift runtime issue due to its variance between Swift versions and optimization settings. New Xcode and Swift versions may have fixed it.

Indeed. I haven't seen this issue anymore in the last weeks.

Yes, I have not encountered this issue anymore. Thanks!

Was this page helpful?
0 / 5 - 0 ratings