Azure / azure-sdk-for-ios

iOS client SDKs for Microsoft Azure
https://azure.github.io/azure-sdk-for-ios/
MIT License
185 stars 88 forks source link

[BUG] App crashes after calling createCallAgent #1818

Closed eskizyen closed 1 month ago

eskizyen commented 2 months ago

Describe the bug Updated SDK from 2.9.0 to 2.11.0, after calling createCallAgent app crashes with an exception 'Unexpected CallAgent type'. Crash doesn't happen with version 2.9.0.

Exception or Stack Trace

Terminating app due to uncaught exception 'ACSException', reason: 'Unexpected CallAgent type' First throw call stack: (0x1a7468f20 0x19f2fa018 0x1a75676dc 0x119e01d9c 0x112f44b98 0x112f467bc 0x112f56d58 0x112f5690c 0x1a743b710 0x1a7438914 0x1a7437cd8 0x1ec2e81a8 0x1a9a7090c 0x1a9b249d0 0x1023b151c 0x1caae9e4c) libc++abi: terminating due to uncaught exception of type NSException

AzureCommunicationCalling`-[ACSCallClient createCallAgentWithOptionsInternal:callAgentOptions:teamsCallAgentOptions:withCompletionHandler:withTeamsCompletionHandler:]: 0x11a6d9594 <+0>: sub sp, sp, #0xe0 0x11a6d9598 <+4>: stp x26, x25, [sp, #0x90] 0x11a6d959c <+8>: stp x24, x23, [sp, #0xa0] 0x11a6d95a0 <+12>: stp x22, x21, [sp, #0xb0] 0x11a6d95a4 <+16>: stp x20, x19, [sp, #0xc0] 0x11a6d95a8 <+20>: stp x29, x30, [sp, #0xd0] 0x11a6d95ac <+24>: add x29, sp, #0xd0 0x11a6d95b0 <+28>: mov x23, x6 0x11a6d95b4 <+32>: mov x22, x5 0x11a6d95b8 <+36>: mov x21, x4 0x11a6d95bc <+40>: mov x20, x3 0x11a6d95c0 <+44>: mov x24, x1 0x11a6d95c4 <+48>: mov x25, x0 0x11a6d95c8 <+52>: mov x0, x2 0x11a6d95cc <+56>: bl 0x11a7499d4 ; symbol stub for: objc_retain 0x11a6d95d0 <+60>: mov x19, x0 0x11a6d95d4 <+64>: mov x0, x20 0x11a6d95d8 <+68>: bl 0x11a7499d4 ; symbol stub for: objc_retain 0x11a6d95dc <+72>: mov x20, x0 0x11a6d95e0 <+76>: mov x0, x21 0x11a6d95e4 <+80>: bl 0x11a7499d4 ; symbol stub for: objc_retain 0x11a6d95e8 <+84>: mov x21, x0 0x11a6d95ec <+88>: mov x0, x22 0x11a6d95f0 <+92>: bl 0x11a7499d4 ; symbol stub for: objc_retain 0x11a6d95f4 <+96>: mov x22, x0 0x11a6d95f8 <+100>: mov x0, x23 0x11a6d95fc <+104>: bl 0x11a7499d4 ; symbol stub for: objc_retain 0x11a6d9600 <+108>: mov x23, x0 0x11a6d9604 <+112>: cbz x19, 0x11a6d96d0 ; <+316> 0x11a6d9608 <+116>: mov x0, #0x0 0x11a6d960c <+120>: mov x1, #0x0 0x11a6d9610 <+124>: bl 0x11a749170 ; symbol stub for: dispatch_get_global_queue 0x11a6d9614 <+128>: mov x29, x29 0x11a6d9618 <+132>: bl 0x11a7499f8 ; symbol stub for: objc_retainAutoreleasedReturnValue 0x11a6d961c <+136>: mov x26, x0 0x11a6d9620 <+140>: adrp x8, 1063 0x11a6d9624 <+144>: ldr x8, [x8, #0x498] 0x11a6d9628 <+148>: str x8, [sp, #0x8] 0x11a6d962c <+152>: adrp x8, 518 0x11a6d9630 <+156>: ldr d0, [x8, #0x290] 0x11a6d9634 <+160>: adr x8, #0x198 ; 140-[ACSCallClient createCallAgentWithOptionsInternal:callAgentOptions:teamsCallAgentOptions:withCompletionHandler:withTeamsCompletionHandler:]_block_invoke_2 0x11a6d9638 <+164>: nop
0x11a6d963c <+168>: adrp x9, 1636 0x11a6d9640 <+172>: add x9, x9, #0x9e8 ; __block_descriptor_88_e8_32s40s48s56s64bs72bs_e5_v8?0l 0x11a6d9644 <+176>: str d0, [sp, #0x10] 0x11a6d9648 <+180>: stp x8, x9, [sp, #0x18] 0x11a6d964c <+184>: add x8, sp, #0x8 0x11a6d9650 <+188>: str x25, [sp, #0x28] 0x11a6d9654 <+192>: add x25, x8, #0x40 0x11a6d9658 <+196>: mov x0, x22 0x11a6d965c <+200>: bl 0x11a7499d4 ; symbol stub for: objc_retain 0x11a6d9660 <+204>: str x0, [sp, #0x48] 0x11a6d9664 <+208>: mov x0, x23 0x11a6d9668 <+212>: bl 0x11a7499d4 ; symbol stub for: objc_retain 0x11a6d966c <+216>: str x0, [sp, #0x50] 0x11a6d9670 <+220>: mov x0, x19 0x11a6d9674 <+224>: bl 0x11a7499d4 ; symbol stub for: objc_retain 0x11a6d9678 <+228>: str x0, [sp, #0x30] 0x11a6d967c <+232>: mov x0, x20 0x11a6d9680 <+236>: bl 0x11a7499d4 ; symbol stub for: objc_retain 0x11a6d9684 <+240>: str x0, [sp, #0x38] 0x11a6d9688 <+244>: str x24, [sp, #0x58] 0x11a6d968c <+248>: mov x0, x21 0x11a6d9690 <+252>: bl 0x11a7499d4 ; symbol stub for: objc_retain 0x11a6d9694 <+256>: str x0, [sp, #0x40] 0x11a6d9698 <+260>: add x1, sp, #0x8 0x11a6d969c <+264>: mov x0, x26 0x11a6d96a0 <+268>: bl 0x11a749158 ; symbol stub for: dispatch_async -> 0x11a6d96a4 <+272>: mov x0, x26 0x11a6d96a8 <+276>: bl 0x11a7499c8 ; symbol stub for: objc_release 0x11a6d96ac <+280>: ldr x0, [sp, #0x40] 0x11a6d96b0 <+284>: bl 0x11a7499c8 ; symbol stub for: objc_release 0x11a6d96b4 <+288>: ldr x0, [sp, #0x38] 0x11a6d96b8 <+292>: bl 0x11a7499c8 ; symbol stub for: objc_release 0x11a6d96bc <+296>: ldr x0, [sp, #0x30] 0x11a6d96c0 <+300>: bl 0x11a7499c8 ; symbol stub for: objc_release 0x11a6d96c4 <+304>: ldr x0, [sp, #0x50] 0x11a6d96c8 <+308>: bl 0x11a7499c8 ; symbol stub for: objc_release 0x11a6d96cc <+312>: b 0x11a6d9724 ; <+400> 0x11a6d96d0 <+316>: adrp x8, 1063 0x11a6d96d4 <+320>: ldr x8, [x8, #0x498] 0x11a6d96d8 <+324>: str x8, [sp, #0x60] 0x11a6d96dc <+328>: adrp x8, 518 0x11a6d96e0 <+332>: ldr d0, [x8, #0x290] 0x11a6d96e4 <+336>: adr x8, #0x8c ;
140-[ACSCallClient createCallAgentWithOptionsInternal:callAgentOptions:teamsCallAgentOptions:withCompletionHandler:withTeamsCompletionHandler:]_block_invoke 0x11a6d96e8 <+340>: nop
0x11a6d96ec <+344>: adrp x9, 1636 0x11a6d96f0 <+348>: add x9, x9, #0x708 ; __block_descriptor_48_e8_32s40bs_e5_v8?0l 0x11a6d96f4 <+352>: str d0, [sp, #0x68] 0x11a6d96f8 <+356>: stp x8, x9, [sp, #0x70] 0x11a6d96fc <+360>: add x8, sp, #0x60 0x11a6d9700 <+364>: str x25, [sp, #0x80] 0x11a6d9704 <+368>: add x25, x8, #0x28 0x11a6d9708 <+372>: mov x0, x22 0x11a6d970c <+376>: bl 0x11a7499d4 ; symbol stub for: objc_retain 0x11a6d9710 <+380>: str x0, [sp, #0x88] 0x11a6d9714 <+384>: adrp x0, 1063 0x11a6d9718 <+388>: ldr x0, [x0, #0x7a8] 0x11a6d971c <+392>: add x1, sp, #0x60 0x11a6d9720 <+396>: bl 0x11a749158 ; symbol stub for: dispatch_async 0x11a6d9724 <+400>: ldr x0, [x25] 0x11a6d9728 <+404>: bl 0x11a7499c8 ; symbol stub for: objc_release 0x11a6d972c <+408>: mov x0, x23 0x11a6d9730 <+412>: bl 0x11a7499c8 ; symbol stub for: objc_release 0x11a6d9734 <+416>: mov x0, x22 0x11a6d9738 <+420>: bl 0x11a7499c8 ; symbol stub for: objc_release 0x11a6d973c <+424>: mov x0, x21 0x11a6d9740 <+428>: bl 0x11a7499c8 ; symbol stub for: objc_release 0x11a6d9744 <+432>: mov x0, x20 0x11a6d9748 <+436>: bl 0x11a7499c8 ; symbol stub for: objc_release 0x11a6d974c <+440>: mov x0, x19 0x11a6d9750 <+444>: bl 0x11a7499c8 ; symbol stub for: objc_release 0x11a6d9754 <+448>: ldp x29, x30, [sp, #0xd0] 0x11a6d9758 <+452>: ldp x20, x19, [sp, #0xc0] 0x11a6d975c <+456>: ldp x22, x21, [sp, #0xb0] 0x11a6d9760 <+460>: ldp x24, x23, [sp, #0xa0] 0x11a6d9764 <+464>: ldp x26, x25, [sp, #0x90] 0x11a6d9768 <+468>: add sp, sp, #0xe0 0x11a6d976c <+472>: ret

To Reproduce Call createCallAgent on call client.

Code Snippet callClient.createCallAgent(userCredential: credentials)

Expected behavior No crash happens.

Setup (please complete the following information):

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

tjprescott commented 2 months ago

@raosanat can you take a look?

raosanat commented 2 months ago

Looks like you are using the incorrect token for the CallAgent type that you are trying to create. If you are using a MicrosoftTeamsUserIdentifier please follow the documentation and code samples.

eskizyen commented 2 months ago

Unfortunately the issue is not about setup. It works for SDK version 2.9.0 but not with 2.11.0

raosanat commented 2 months ago

So in 2.9.0 version and below we did allow creating a CallAgent with a Teams token. But 2.9.0 and above we have introduced a better experience with introduction of TeamsCallAgent which can be created using a Teams token. Just to confirm you are using a MicrosoftTeamsUserIdentifier type ?

eskizyen commented 1 month ago

In my case I don't start a call so I don't use MicrosoftTeamsUserIdentifier or any other identifier. Call is started in backend and I accept it. Just in case I tried to create teams agent callClient.createTeamsCallAgent(userCredential: credentials) and faced the same crash.

In backend they use Call Automation SDK.

More specifically: azure-communication-callautomation Version 1.1.0 azure-communication-identity Version 1.5.0 azure-communication.networktraversal Version 1.1.0-beta.2

manojsharmadcx commented 1 month ago

Hi @raosanat, I am also facing similar issue. Before upgrading to 2.11.0, the following code worked fine for phone calling. After upgrade have started receiving error. Looks like if we don't pass any options, it assumes "teams" by default and hence crashes. Any suggestions to fix the error:

Previously working code:

func setupCallAgent() {
        var userCredential: CommunicationTokenCredential?
        do {
            userCredential = try CommunicationTokenCredential(token: accessToken)
        } catch {
            print("@@ ERROR: It was not possible to create user credential. \(error.localizedDescription)")
            return
        }

        self.callClient = CallClient()

        self.callClient.createCallAgent(userCredential: userCredential!) {  (agent, error) in

            if let error = error {
                print("@@ ERROR: It was not possible to create a call agent. \(error.localizedDescription)")
                return
            }

            print("@@ Call agent type: \(type(of: callAgent))")
            self.callAgent = agent
            print("@@ Call agent successfully created.")
            self.startCall()
        }
    }
**Error after upgrade:**

Terminating app due to uncaught exception 'ACSException', reason: 'Unexpected CallAgent type' First throw call stack: ( 0 CoreFoundation 0x0000000118859571 exceptionPreprocess + 242 1 libobjc.A.dylib 0x000000010e4c67e8 objc_exception_throw + 48 2 CoreFoundation 0x000000011885944f -[NSException initWithCoder:] + 0 3 AzureCommunicationCalling 0x0000000114b8652b 140-[ACSCallClient createCallAgentWithOptionsInternal:callAgentOptions:teamsCallAgentOptions:withCompletionHandler:withTeamsCompletionHandler:]_block_invoke_4 + 363

raosanat commented 1 month ago

Re-opening the issue to investigate.

raosanat commented 1 month ago

Thanks for reporting the issue, we are working on fixing the bug.

lucianopa-msft commented 1 month ago

@eskizyen This should be fixed on https://github.com/Azure/Communication/releases/tag/v2.13.0-beta.1, can you please verify? Feel free to reopen if is still an issue