twilio / twilio-voice-ios

Programmable Voice SDK by Twilio
https://www.twilio.com/voice
38 stars 14 forks source link

TwilioVoice 3.1.0 Crash - NSInvalidArgumentException #13

Closed jbohman closed 5 years ago

jbohman commented 5 years ago

Description

I'm trying to use TwilioVoice 3.1.0 (through CocoaPods) and integrate it as a native module in react-native but whenever I try to use connectWithOptions it crashes.

If you need any more information, I'll be happy to help resolve this issue.

Steps to Reproduce

  1. Start app
  2. Navigate to section that uses the native module (from react native)
  3. Wait for server to return access token
  4. Access token is sent to connect function
  5. Crash

Code

I can't share all code, but this is the main part of the code and directly after the last line it crashes.

    var iceServers: Array<TVOIceServer> = Array()
    let iceServer1: TVOIceServer = TVOIceServer(urlString: "stun:global.stun.twilio.com:3478?transport=udp",
                                                username: "",
                                                password: "")
    iceServers.append(iceServer1)

    let iceOptions: TVOIceOptions = TVOIceOptions { (builder) in
        builder.servers = iceServers
    }

    let connectOptions: TVOConnectOptions = TVOConnectOptions(accessToken: token) { (builder) in
        builder.params = [twimlParamTo : toParam]
        builder.iceOptions = iceOptions
    }

    self.call = TwilioVoice.connect(with: connectOptions, delegate: self)

I've tried to run both on the main queue and setup a new serial queue, result is still the same.

Expected Behavior

No crash

Actual Behavior

It crashes with the following trace:

2019-06-01 20:18:45.030495+0200 app[53534:675280] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[5]'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000109c4a6fb __exceptionPreprocess + 331
    1   libobjc.A.dylib                     0x000000010861cac5 objc_exception_throw + 48
    2   CoreFoundation                      0x0000000109b98ddc _CFThrowFormattedException + 194
    3   CoreFoundation                      0x0000000109cb6c31 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 321
    4   CoreFoundation                      0x0000000109c463db +[NSDictionary dictionaryWithObjects:forKeys:count:] + 59
    5   TwilioVoice                         0x0000000106417840 -[TVOCall publishConnectionEvent:error:] + 1026
    6   TwilioVoice                         0x000000010641ab7c _ZN6twilio5voice20EventObserverAdapter7onEventENSt3__13mapINS2_12basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEES9_NS2_4lessIS9_EENS7_INS2_4pairIKS9_S9_EEEEEE + 1264
    7   TwilioVoice                         0x00000001068254e3 _ZNSt3__110__function6__funcIZN6twilio5voice8CallImpl9postEventERNS_3mapINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEESB_NS_4lessISB_EENS9_INS_4pairIKSB_SB_EEEEEEE4$_37NS9_ISK_EEFvvEEclEv + 227
    8   libdispatch.dylib                   0x000000010db8ed7f _dispatch_call_block_and_release + 12
    9   libdispatch.dylib                   0x000000010db8fdb5 _dispatch_client_callout + 8
    10  libdispatch.dylib                   0x000000010db9d080 _dispatch_main_queue_callback_4CF + 1540
    11  CoreFoundation                      0x0000000109bb18a9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    12  CoreFoundation                      0x0000000109babf56 __CFRunLoopRun + 2310
    13  CoreFoundation                      0x0000000109bab302 CFRunLoopRunSpecific + 626
    14  GraphicsServices                    0x00000001117da2fe GSEventRunModal + 65
    15  UIKitCore                           0x00000001151a5ba2 UIApplicationMain + 140
    16  app                            0x0000000101a72410 main + 112
    17  libdyld.dylib                       0x000000010dc04541 start + 1
    18  ???                                 0x0000000000000002 0x0 + 2
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Reproduces How Often

Every time I've tried it

Logs

Versions

All relevant version information for the issue.

Voice iOS SDK

3.1.0 via CocoaPods

Xcode

1.0

iOS Version

12.2

iOS Device

Both simulator (iPhone XR) and real device (iPhone XS)

bobiechen-twilio commented 5 years ago

Hi @jbohman

Sorry for not responding back to you sooner since this does sound a really bad experience. Thanks for reporting the issue with detailed descriptions. I've checked the source where the crash happened though it seem odd that the object being inserted into the dictionary was nil.

Could you please provide us the .trace level SDK log so we can look into and figure out what caused the crash?

Couple of question:

Thanks,

jbohman commented 5 years ago

Hello @bchen-twilio

Thank you for your response, I've attached a trace log on a crash from iOS Simulator, iPhone XR, twilio.log. I can try on a real device tomorrow if that is better.

  • Does the crash happen if the no ICE options are provided to the connect options when making the outgoing call?

When you say no ICE options, do you mean just not passing it? Because if I don't set iceOptions at all it still crashes.

  • When did the crash happen? does it happen before you can hear any audio of the call or does it happen in the middle or at the end of the call?

It happens before I hear any audio at all, I'm calling into a conference call that is not active yet, I'm the first participant.

In the JS code I have running in the browser for the conference, I'm using twilio-client library and setup a Twilio.Device before I call into the conference and there I wait for the device to get ready before calling connect. Is it something I should do here as well (couldn't find it in the documentation)?

A note as well, I've not set up a VoIP Service Certificate from Apple. As I understand it, it is only used for incoming call but here I want to make an outgoing call to a conference.

  • I tried running the Swift quickstart, which uses the Swift 4 compiler, but was unfortunately not able to reproduce the crash with the same ICE options configuration in your description. Could you share some more information about your Swift environment?

I'm running a React Native project and this is a native module written in Swift, I noticed that I missed the Xcode version in my initial post, it is 10.2 and the Swift version is 5.

This is my first attempt at writing a native module in React Native and there is a high chance I'm doing something wrong. If we don't figure out anything in the next couple of days my goal is to extract the relevant code into a separate repository and try to reproduce the problem there. But it will take a couple of days until I have the time to do it properly.

Best regards,

Joel

bobiechen-twilio commented 5 years ago

Hi @jbohman

Thanks for the updates 👍.

After some debugging I have identified that the crash is due to one of the properties of the TVOCall object has not yet been initialized before the SDK tries to insert it to a dictionary. This happens especially easily when the first time a call is made while the user is prompted for microphone permission but the underlying signaling stack is still running and the object is still nil.

We will provide a patch fix asap.

Thanks again for reporting the issue. -bobie

bobiechen-twilio commented 5 years ago

Hi Joel,

We've just release the Voice iOS SDK 3.1.1 which includes the fix for this issue. Please update and let us know if the issue is fixed. Thanks again for reporting the issue.

Thanks, -bobie

jbohman commented 5 years ago

Hello @bchen-twilio

I can confirm that my app no longer crashes after the update. Thank you very much for the quick solution!

But I've run into another issue now, I always get 503 Service Unavailable error in didFailToConnectWithError method. Should I create a new issue or what is the correct process? Could it be related to why the value was nil?

bobiechen-twilio commented 5 years ago

Hi Joel,

Thanks for confirming that the update works for you!

I am closing this issue as fixed but yes, for the 503 error, please feel free to create a new issue with the steps, environment configuration and the .trace level SDK log so we can investigate.

-bobie

Anilkumar18 commented 1 year ago

Hello @bobiechen-twilio I am running the following version TwilioVoice 6.2.2 which crashes due to the same issue which was reported above. I have attached the trace below for your reference

2022-11-18 14:44:09.489177+0530 app[607:66012] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[8]'
*** First throw call stack:
(0x181e35c9c 0x198fe9758 0x181f2e91c 0x181f38b34 0x181df5b4c 0x181e12edc 0x12019e7cc 0x1201b7b44 0x1201a5044 0x1201a41e4 0x18259a4c0 0x1825aa8d0 0x10623c718 0x10623df94 0x106245150 0x106245e08 0x1062514e8 0x1dbeb1e84 0x1dbeb19f0)

Xcode 13.3

iOS Version 15.2 & 15.1

iOS Device iPhone XR & iPhone 6s

bobiechen-twilio commented 1 year ago

Hi @Anilkumar18 Thanks for reaching out. We have discontinued the support of the Voice iOS SDK 3.x. Please upgrade and integrate with the latest version of the SDK.

Anilkumar18 commented 1 year ago

Hi @bobiechen-twilio Thanks for responding back. I used SDK version 6.2.2 and even on 6.4.3 facing the same issue. I has issue while TwilioVoiceSDK.register and TwilioVoiceSDK.unregister the SDK. Attached error log above.