apollographql / apollo-ios

📱  A strongly-typed, caching GraphQL client for iOS, written in Swift.
https://www.apollographql.com/docs/ios/
MIT License
3.88k stars 726 forks source link

App crashing while running second time. #2886

Closed kc-bandari closed 1 year ago

kc-bandari commented 1 year ago

Summary

Hi,

I created a framework that uses graphQL and distributes over cocoa pods. But the App crashes with the following message.

dyld[2864]: Symbol not found: _$s6Apollo0A11InterceptorP14interceptAsync5chain7request8response10completionyAA12RequestChainC_AA11HTTPRequestCyqd__GAA12HTTPResponseCyqd__GSgys6ResultOyAA13GraphQLResultVy4DataQyd__Gs5Error_pGctAA0N11QLOperationRd__lFTq Referenced from: <839B55F6-A286-398B-85CC-3B5A70F61E37> /Users/chaitba2/Library/Developer/CoreSimulator/Devices/738A1AA1-E329-4715-9992-4042F8F07494/data/Containers/Bundle/Application/CB7F693B-F7C3-4271-8DA5-97C73A6BB6CA/Test.app/Frameworks/MyFramework.framework/MyFramework Expected in: <29289C10-90E5-30CF-A497-A6CD4B93D5BA> /Users/chaitba2/Library/Developer/CoreSimulator/Devices/738A1AA1-E329-4715-9992-4042F8F07494/data/Containers/Bundle/Application/CB7F693B-F7C3-4271-8DA5-97C73A6BB6CA/Test.app/Frameworks/Apollo.framework/Apollo Symbol not found: _$s6Apollo0A11InterceptorP14interceptAsync5chain7request8response10completionyAA12RequestChainC_AA11HTTPRequestCyqd__GAA12HTTPResponseCyqd__GSgys6ResultOyAA13GraphQLResultVy4DataQyd__Gs5Error_pGctAA0N11QLOperationRd__lFTq Referenced from: <839B55F6-A286-398B-85CC-3B5A70F61E37> /Users/chaitba2/Library/Developer/CoreSimulator/Devices/738A1AA1-E329-4715-9992-4042F8F07494/data/Containers/Bundle/Application/CB7F693B-F7C3-4271-8DA5-97C73A6BB6CA/Test.app/Frameworks/MyFramework.framework/MyFramework Expected in: <29289C10-90E5-30CF-A497-A6CD4B93D5BA> /Users/chaitba2/Library/Developer/CoreSimulator/Devices/738A1AA1-E329-4715-9992-4042F8F07494/data/Containers/Bundle/Application/CB7F693B-F7C3-4271-8DA5-97C73A6BB6CA/Test.app/Frameworks/Apollo.framework/Apollo dyld config: DYLD_SHARED_CACHE_DIR=/Users/chaitba2/Library/Developer/CoreSimulator/Caches/dyld/22D68/com.apple.CoreSimulator.SimRuntime.iOS-16-2.20C52 DYLD_ROOT_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot DYLD_LIBRARY_PATH=/Users/chaitba2/Library/Developer/Xcode/DerivedData/Test-gzjcnuvbnqcsiqdsdpknvofjxumr/Build/Products/Debug-iphonesimulator:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libMainThreadChecker.dylib:/usr/lib/libRPAC.dylib:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib DYLD_FRAMEWORK_PATH=/Users/chaitba2/Library/Developer/Xcode/DerivedData/Test-gzjcnuvbnqcsiqdsdpknvofjxumr/Build/Products/Debug-iphonesimulator DYLD_FALLBACK_FRAMEWORK_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks DYLD_FALLBACK_LIBRARY_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib

Version

1.0.7

Steps to reproduce the behavior

Installed the app via the framework created in Swift.

Logs

No response

Anything else?

No response

calvincestari commented 1 year ago

Hi @kc-bandari, can you provide a sample app that reproduces the crash please.

kc-bandari commented 1 year ago

It is embedded in my framework and I need to share the framework in the sample app.

kc-bandari commented 1 year ago

For querying graphQL here are the classes am using.

final class NetworkClient {
    static let shared = NetworkClient()
    lazy var apollo = ApolloClient(url: URL(string: KogoURLs.kogoBaseURL.value)!)
    lazy var apolloWithToken: ApolloClient = {
        let client = URLSessionClient()
        let cache = InMemoryNormalizedCache()
        let store = ApolloStore(cache: cache)
        let provider = NetworkInterceptorProvider(client: client, store: store)
        let url = URL(string: _BASEURL_)!
        let transport = RequestChainNetworkTransport(interceptorProvider: provider, endpointURL: url)
        return ApolloClient(networkTransport: transport, store: store)
    }()
}
class TokenAddingInterceptor: ApolloInterceptor {
    func interceptAsync<Operation: GraphQLOperation>(
        chain: RequestChain,
        request: HTTPRequest<Operation>,
        response: HTTPResponse<Operation>?,
        completion: @escaping (Result<GraphQLResult<Operation.Data>, Error>) -> Void) {
            if let token = KeychainHelper.shared.getStringFor(TOKEN) {
                request.addHeader(name: "Authorization", value: token)
            } 
            chain.proceedAsync(request: request, response: response, completion: completion)
    }
}
class NetworkInterceptorProvider: DefaultInterceptorProvider {
    override func interceptors<Operation: GraphQLOperation>(for operation: Operation) -> [ApolloInterceptor] {
        var interceptors = super.interceptors(for: operation)
        interceptors.insert(TokenAddingInterceptor(), at: 0)
        return interceptors
    }
}
kc-bandari commented 1 year ago

Also please find the details from the device crash log.

Incident Identifier: F156A371-850F-426B-8A7E-52231737F158
CrashReporter Key:   28e29289fc32075d26d7a2788f409980b0ea311c
Hardware Model:      iPhone14,3
Process:             Test [5905]
Path:                /private/var/containers/Bundle/Application/55CADAE3-C3DB-4E4A-BC6C-7CD72E04EFE6/Test.app/Test
Identifier:          com.xyz.DEV
Version:             1.0 (1)
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           com.alcon.fitSCANDEV [3378]

Date/Time:           2023-03-21 21:01:50.8032 +0530
Launch Time:         2023-03-21 21:01:50.7911 +0530
OS Version:          iPhone OS 16.3.1 (20D67)
Release Type:        User
Baseband Version:    2.40.01
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Termination Reason: DYLD 4 Symbol missing
Symbol not found: _$s6Apollo0A11InterceptorP14interceptAsync5chain7request8response10completionyAA12RequestChainC_AA11HTTPRequestCyqd__GAA12HTTPResponseCyqd__GSgys6ResultOyAA13GraphQLResultVy4DataQyd__Gs5Error_pGctAA0N11QLOperationRd__lFTq
Referenced from: <CF9EA714-86F8-3036-AF21-A12CB90E2AF4> /Volumes/VOLUME/*/Test.app/Frameworks/KogoAuto.framework/KogoAuto
Expected in:     <B2DCCFEC-ECD9-3048-90F8-4B7DD10B1C90> /Volumes/VOLUME/*/Test.app/Frameworks/Apollo.framework/Apollo
(terminated at launch; ignore backtrace)

Triggered by Thread:  0

Thread 0 Crashed:
0   dyld                                   0x1c0b92ebc __abort_with_payload + 8
1   dyld                                   0x1c0b9c674 abort_with_payload_wrapper_internal + 104
2   dyld                                   0x1c0b9c6a8 abort_with_payload + 16
3   dyld                                   0x1c0b406b4 dyld4::halt(char const*) + 328
4   dyld                                   0x1c0b3e92c dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 4092
5   dyld                                   0x1c0b3c8d4 start + 2388

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000006   x1: 0x0000000000000004   x2: 0x000000016d9b4b60   x3: 0x00000000000001ee
    x4: 0x000000016d9b4760   x5: 0x0000000000000000   x6: 0x000000016d9b3660   x7: 0x000000016d9b4148
    x8: 0x0000000000000020   x9: 0x0000000000000009  x10: 0x0000000000000001  x11: 0x000000000000000a
   x12: 0x0000000000000000  x13: 0x0000000000000035  x14: 0x000000010291775c  x15: 0x000000016d9b3908
   x16: 0x0000000000000209  x17: 0x00000001c0b8f7bc  x18: 0x0000000000000000  x19: 0x0000000000000000
   x20: 0x000000016d9b4760  x21: 0x00000000000001ee  x22: 0x000000016d9b4b60  x23: 0x0000000000000004
   x24: 0x0000000000000006  x25: 0x000000016d9b7518  x26: 0x0000000000000000  x27: 0x0000000102479a60
   x28: 0x00000001f93b2200   fp: 0x000000016d9b4730   lr: 0x00000001c0b9c674
    sp: 0x000000016d9b46f0   pc: 0x00000001c0b92ebc cpsr: 0x00001000
   far: 0x00000001f93b2cf0  esr: 0x56000080  Address size fault

Binary Images:
       0x1c0b27000 -        0x1c0baa093 dyld arm64e  <4b042f280d1430eca1de3dbb10866ad7> /usr/lib/dyld

EOF
calvincestari commented 1 year ago

@kc-bandari I meant a working standalone app. If you can't reproduce it in a standalone app you could share with us it may indicate it's something specific to your project, which would be more difficult to debug.

kc-bandari commented 1 year ago

Hi I cannot share the SDK as it is against the org policy. It is happening in the SDK where the it worked fine earlier. Please let me know if there is any other way to investigate without sharing the SDK.

FYI: Am using SurMagic to generate xcframework.

calvincestari commented 1 year ago

I'm not asking for access to your SDK. Create another standalone SDK or app that replicates the crash and share that instead.

kc-bandari commented 1 year ago

Tried creating standalone SDK to reproduce crash but that was working as expected.

calvincestari commented 1 year ago

OK, so that indicates that it's probably something specific to your project configuration. Given that it uses the symbol but can't find it at runtime hints to a linking problem. I would expect linking problems to be consistent so why this works the first time but not the second is very confusing. 😕

kc-bandari commented 1 year ago

This got cleared by commenting use_framework line in Pod file. Thank you for quick response. Closing this issue.