Moya: Crash in release build configuration when using Swift Package Manager

Created on 18 Nov 2019  路  4Comments  路  Source: Moya/Moya

Hi there,

I'm experiencing a crash when the app is built using Xcode default generated build configuration called Release, thus I think it may be related to the compiler optimizations.

This is the LLDB log:

TestSPM was compiled with optimization - stepping may behave oddly; variables may not be available.
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
    frame #0: 0x000000010a8a6d38 TestSPM`method descriptor for Moya.MoyaProvider.inflightRequests.getter : Swift.Dictionary<Moya.Endpoint, Swift.Array<(Result.Result<Moya.Response, Moya.MoyaError>) -> ()>> + 52
  * frame #1: 0x000000010a82ad76 TestSPM`MoyaProvider.requestNormal(target=<no summary available>, callbackQueue=nil, progress=nil, completion=0x000000010a821590 TestSPM`closure #1 (Result.Result<Moya.Response, Moya.MoyaError>) -> () in TestSPM.AppDelegate.application(_: __C.UIApplication, didFinishLaunchingWithOptions: Swift.Optional<Swift.Dictionary<__C.UIApplicationLaunchOptionsKey, Any>>) -> Swift.Bool at AppDelegate.swift:18, self=<no summary available>) at MoyaProvider+Internal.swift:24:29 [opt]
    frame #2: 0x000000010a831aa4 TestSPM`MoyaProvider.request(target=<no summary available>, callbackQueue=nil, progress=nil, completion=0x000000010a821590 TestSPM`closure #1 (Result.Result<Moya.Response, Moya.MoyaError>) -> () in TestSPM.AppDelegate.application(_: __C.UIApplication, didFinishLaunchingWithOptions: Swift.Optional<Swift.Dictionary<__C.UIApplicationLaunchOptionsKey, Any>>) -> Swift.Bool at AppDelegate.swift:18, self=<no summary available>) at MoyaProvider.swift:124:16 [opt]
    frame #3: 0x000000010a821e6d TestSPM`specialized AppDelegate.application(_:didFinishLaunchingWithOptions:) at AppDelegate.swift:18:32 [opt]
    frame #4: 0x000000010a821785 TestSPM`@objc AppDelegate.application(_:didFinishLaunchingWithOptions:) [inlined] TestSPM.AppDelegate.application(_: __C.UIApplication, didFinishLaunchingWithOptions: Swift.Optional<Swift.Dictionary<__C.UIApplicationLaunchOptionsKey, Any>>) -> Swift.Bool at <compiler-generated>:0 [opt]
    frame #5: 0x000000010a821780 TestSPM`@objc AppDelegate.application(_:didFinishLaunchingWithOptions:) at <compiler-generated>:17 [opt]
    frame #6: 0x0000000118b8c788 UIKitCore`-[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 232
    frame #7: 0x0000000118b8e197 UIKitCore`-[UIApplication _callInitializationDelegatesWithActions:forCanvas:payload:fromOriginatingProcess:] + 3980
    frame #8: 0x0000000118b93ce6 UIKitCore`-[UIApplication _runWithMainScene:transitionContext:completion:] + 1281
    frame #9: 0x00000001182ca402 UIKitCore`-[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:] + 179
    frame #10: 0x0000000118b90286 UIKitCore`-[UIApplication _compellApplicationLaunchToCompleteUnconditionally] + 59
    frame #11: 0x0000000118b90585 UIKitCore`-[UIApplication _run] + 754
    frame #12: 0x0000000118b95b48 UIKitCore`UIApplicationMain + 1621
    frame #13: 0x000000010a8219b2 TestSPM`main at AppDelegate.swift:13:7 [opt]
    frame #14: 0x000000010f8d4c25 libdyld.dylib`start + 1
    frame #15: 0x000000010f8d4c25 libdyld.dylib`start + 1

Steps to reproduce

  • Create an empty iOS project (Single View Application)
  • Add Moya (just the Moya target) as a dependency using SPM (using Xcode GUI), latest version up to the next major, currently 13.0.1
  • Add a TargetType file and add some basic code as soon as possible, like, for example, the following in your AppDelegate's application(_:didFinishLaunchingWithOptions:)
MoyaProvider<YourTargetType>().request(.yourEndpoint) { result in
    print(result)
}
  • Edit your Run scheme to use Release build configuration instead of Debug one
  • Run and wait for crash to happen

More info:

I'm using Xcode Version 11.2.1 (11B500).

I am available if any further clarifications are needed and take the chance to thank you for your great work!

bug?

Most helpful comment

@artemisia-absynthium @sunshinejr
I may have some time this week to take a look on that :)
@sunshinejr Congratulations and best wishes for your new born 馃帀

All 4 comments

Hey @artemisia-absynthium, thank you so much for this bug report! I recently got a similar report for SwiftyUserDefaults and the reporter said that many other projects also have the issue and it might be connected to the SPM with Generics. They also said that CocoaPods didn鈥檛 have this problem.

Honestly, I鈥檓 not sure what鈥檚 going on and I鈥檓 unable to check it quickly as I鈥檓 quite busy taking care of my newborn atm, so I cannot promise any dates. Maybe someone else from @Moya/contributors could take a look?

I also wonder if its just a bug in Swift toolchain provided in Xcode 11.2.1? Have you tried any other Xcode versions maybe?

@sunshinejr Best wishes to the newly dad!! 馃帀Don't worry, I didn't mean to put pressure, I've switched back to Cocoapods to make it work again. Just wanted to let the team know!

I have just tried with the other toolchains included in Xcode 11.x (Swift 5.1 and Swift 5.1.1) but that didn't change the situation.

@artemisia-absynthium @sunshinejr
I may have some time this week to take a look on that :)
@sunshinejr Congratulations and best wishes for your new born 馃帀

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fenixsolorzano picture fenixsolorzano  路  3Comments

JianweiWangs picture JianweiWangs  路  3Comments

ghost picture ghost  路  3Comments

dimpiax picture dimpiax  路  3Comments

PlutusCat picture PlutusCat  路  3Comments