TuyaInc / tuyasmart_home_ios_sdk

Tuya Smart iOS Home SDK
https://tuyainc.github.io/tuyasmart_home_ios_sdk_doc
50 stars 19 forks source link

Crash after initializing Tuya SDK #40

Closed Paco480 closed 4 years ago

Paco480 commented 4 years ago

Hello,

Our app is crashing after initializing Tuya SDK (perhaps from a background thread)

Thread 3: EXC_BAD_ACCESS (code=2, address=0x101752a80)

Stack trace
===========
Thread 3 Queue : GCDAsyncSocket (serial)
#0  0x0000000101752a80 in read ()
#1  0x0000000101005c2c in -[GCDAsyncSocket doReadData] at /Users/francisco/Developer/tuyatest-ios/Pods/CocoaAsyncSocket/Source/GCD/GCDAsyncSocket.m:5264
#2  0x00000001010034b4 in __66-[GCDAsyncSocket setupReadAndWriteSourcesForNewlyConnectedSocket:]_block_invoke at /Users/francisco/Developer/tuyatest-ios/Pods/CocoaAsyncSocket/Source/GCD/GCDAsyncSocket.m:4224
#3  0x0000000101fecc74 in _dispatch_client_callout ()
#4  0x0000000101fefffc in _dispatch_continuation_pop ()
#5  0x0000000102002610 in _dispatch_source_invoke ()
#6  0x0000000101ff4a4c in _dispatch_lane_serial_drain ()
#7  0x0000000101ff58b4 in _dispatch_lane_invoke ()
#8  0x0000000101fff77c in _dispatch_workloop_worker_thread ()
#9  0x00000001943d9114 in _pthread_wqthread ()
#10 0x00000001943dbcd4 in start_wqthread ()

Console logs
============
2019-12-19 14:09:16.711401+0100 tuyatest[423:39784] [HockeySDK] -[BITCrashManager startManager]_block_invoke/1199 [HockeySDK] WARNING: Detecting crashes is NOT enabled due to running the app with a debugger attached.
2019-12-19 14:09:16.795472+0100 tuyatest[423:39784] upgradeV2ToV3
2019-12-19 14:09:16.798869+0100 tuyatest[423:39784] upgradeV3ToV4
2019-12-19 14:09:16.806157+0100 tuyatest[423:39784] init --- {
    dataVersion = 1;
    domain =     {
        aispeechHttpsUrl = "https://aispeech.tuyaus.com";
        gwApiUrl = "http://a.gw.tuyaus.com/gw.json";
        gwMqttUrl = "mq.gw.tuyaus.com";
        mobileApiUrl = "https://a1.tuyaus.com";
        mobileMediaMqttUrl = "s.tuyaus.com";
        mobileMqttUrl = "mq.mb.tuyaus.com";
        mobileMqttsUrl = "m1.tuyaus.com";
        pxApiUrl = "http://px.tuyaus.com";
        regionCode = AZ;
    };
    ecode = <private>;
    email = "";
    env = "APP_ENV_RELEASE";
    headPic = "";
    mobile = "";
    nickname = "";
    partnerIdentity = p1306808;
    phoneCode = en;
    regFrom = 9;
    sid = <private>;
    snsNickname = "";
    source = 8;
    tempUnit = 1;
    timezoneId = "Europe/Madrid";
    uid = <private>;
    username = 21;
}
2019-12-19 14:09:16.831994+0100 tuyatest[423:39784] connect to host : 52.32.160.79
2019-12-19 14:09:16.834089+0100 tuyatest[423:39784] [MQTTSessionLegacy] initWithClientId:iOS_-<private>
2019-12-19 14:09:16.834302+0100 tuyatest[423:39784] [MQTTSession] init
2019-12-19 14:09:16.901460+0100 tuyatest[423:39784] mqtt connect

}
objc[423]: Class _NSZombie_NSSQLRow is implemented in both ?? (0x282329ef0) and ?? (0x282335500). One of the two will be used. Which one is undefined.
2019-12-19 14:09:17.903242+0100 tuyatest[423:39921] TYRequest response success is tuya.p.time.get {
  "result" : {
    "validTime" : 1800,
    "time" : 1576760957
  },
  "success" : true,
  "status" : "ok",
  "t" : 1576760957797
}
2019-12-19 14:09:18.085252+0100 tuyatest[423:39784] open sqlite db ok.
2019-12-19 14:09:18.101553+0100 tuyatest[423:39925] MQTT connect state : connected (0) (null)
2019-12-19 14:09:18.101867+0100 tuyatest[423:39925] MQTT connected time consuming : 1200
2019-12-19 14:09:19.201918+0100 tuyatest[423:39784] receiveBroadcast : {
    ability = 0;
    active = 2;
    encrypt = 1;
    gwId = <private>;
    ip = "192.168.5.120";
    mode = 0;
    productKey = <private>;
    version = "3.1";
}, active : 2
2019-12-19 14:09:19.203098+0100 tuyatest[423:39784] startTcpConnecting:192.168.5.120
2019-12-19 14:09:19.221677+0100 tuyatest[423:39784] tcpConnected:<private>, time : 0.02
2019-12-19 14:09:19.222421+0100 tuyatest[423:39784] tcp request type : 10, devId : <private>, body : {
    devId = <private>;
    gwId = <private>;
}
2019-12-19 14:09:19.223842+0100 tuyatest[423:39784] kNotificationGatewayInfoUpdate --
2019-12-19 14:09:19.227933+0100 tuyatest[423:39981] [] nw_connection_copy_connected_path [C6] Client called nw_connection_copy_connected_path on unconnected nw_connection
2019-12-19 14:09:19.228085+0100 tuyatest[423:39981] [] tcp_connection_is_cellular No connected path
(lldb) 

How can we solve it?

Thanks in advance

TuyaRonbin commented 4 years ago

Post the contents of podfile.lock

Paco480 commented 4 years ago
PODS:
  - AFNetworking (2.6.1):
    - AFNetworking/NSURLConnection (= 2.6.1)
    - AFNetworking/NSURLSession (= 2.6.1)
    - AFNetworking/Reachability (= 2.6.1)
    - AFNetworking/Security (= 2.6.1)
    - AFNetworking/Serialization (= 2.6.1)
    - AFNetworking/UIKit (= 2.6.1)
  - AFNetworking/NSURLConnection (2.6.1):
    - AFNetworking/Reachability
    - AFNetworking/Security
    - AFNetworking/Serialization
  - AFNetworking/NSURLSession (2.6.1):
    - AFNetworking/Reachability
    - AFNetworking/Security
    - AFNetworking/Serialization
  - AFNetworking/Reachability (2.6.1)
  - AFNetworking/Security (2.6.1)
  - AFNetworking/Serialization (2.6.1)
  - AFNetworking/UIKit (2.6.1):
    - AFNetworking/NSURLConnection
    - AFNetworking/NSURLSession
  - Bolts/Tasks (1.9.0)
  - COAnalytics (0.1.5):
    - AFNetworking
    - COCommons
    - COKissXML
    - GoogleAnalytics
  - COAsynchronous (0.1.4):
    - AFNetworking
    - COCommons
    - COJSON
    - COKissXML
  - CocoaAsyncSocket (7.6.3)
  - COCommons (0.1.31):
    - AFNetworking
    - COCommons/no-arc (= 0.1.31)
    - COJSON
    - COKissXML
  - COCommons/no-arc (0.1.31):
    - AFNetworking
    - COJSON
    - COKissXML
  - COJSON (0.1.0)
  - COKissXML (0.1.3)
  - GoogleAnalytics (3.17.0)
  - HockeySDK (5.1.2):
    - HockeySDK/DefaultLib (= 5.1.2)
  - HockeySDK/DefaultLib (5.1.2)
  - MBProgressHUD (0.9.2)
  - MQTTClient (0.14.0):
    - MQTTClient/Core (= 0.14.0)
  - MQTTClient/Core (0.14.0):
    - MQTTClient/Manager
    - MQTTClient/Min
  - MQTTClient/Manager (0.14.0):
    - MQTTClient/Min
  - MQTTClient/Min (0.14.0)
  - OpenSSL-Universal (1.0.2.17)
  - Parse (1.17.2):
    - Parse/Core (= 1.17.2)
  - Parse/Core (1.17.2):
    - Bolts/Tasks (~> 1.9)
  - Reachability (3.2)
  - TuyaSmartActivatorKit (3.13.1):
    - Reachability
    - TuyaSmartDeviceKit
  - TuyaSmartBaseKit (3.13.4):
    - TuyaSmartUtil
    - YYModel
  - TuyaSmartBLEKit (3.13.1):
    - TuyaSmartActivatorKit
    - TuyaSmartBaseKit
    - TuyaSmartDeviceKit
    - TYBluetooth
  - TuyaSmartBLEMeshKit (3.13.0):
    - OpenSSL-Universal (= 1.0.2.17)
    - TuyaSmartActivatorKit
    - TuyaSmartBaseKit
    - TuyaSmartBLEKit
    - TuyaSmartDeviceKit
    - TYBluetooth
  - TuyaSmartDeviceKit (3.13.12):
    - TuyaSmartBaseKit
    - TuyaSmartMQTTChannelKit
    - TuyaSmartSocketChannelKit
  - TuyaSmartFeedbackKit (3.12.2):
    - TuyaSmartBaseKit
  - TuyaSmartHomeKit (3.13.0):
    - TuyaSmartActivatorKit
    - TuyaSmartBaseKit
    - TuyaSmartBLEKit
    - TuyaSmartBLEMeshKit
    - TuyaSmartDeviceKit
    - TuyaSmartFeedbackKit
    - TuyaSmartMessageKit
    - TuyaSmartMQTTChannelKit
    - TuyaSmartSceneKit
    - TuyaSmartSocketChannelKit
    - TuyaSmartTimerKit
  - TuyaSmartMessageKit (3.12.2):
    - TuyaSmartBaseKit
  - TuyaSmartMQTTChannelKit (3.13.4):
    - MQTTClient (= 0.14.0)
    - TuyaSmartBaseKit
  - TuyaSmartSceneKit (3.13.7):
    - TuyaSmartBaseKit
    - TuyaSmartDeviceKit
  - TuyaSmartSocketChannelKit (3.13.1):
    - CocoaAsyncSocket
    - TuyaSmartBaseKit
  - TuyaSmartTimerKit (3.13.0):
    - TuyaSmartBaseKit
    - TuyaSmartDeviceKit
  - TuyaSmartUtil (3.13.0)
  - TYBluetooth (3.13.3)
  - YYModel (1.0.4)

DEPENDENCIES:
  - AFNetworking (= 2.6.1)
  - COAnalytics
  - COAsynchronous
  - COCommons
  - HockeySDK
  - MBProgressHUD (~> 0.9.1)
  - Parse
  - TuyaSmartHomeKit

SPEC REPOS:
  https://github.com/cocoapods/specs.git:
    - AFNetworking
    - Bolts
    - CocoaAsyncSocket
    - GoogleAnalytics
    - HockeySDK
    - MBProgressHUD
    - MQTTClient
    - OpenSSL-Universal
    - Parse
    - Reachability
    - TuyaSmartActivatorKit
    - TuyaSmartBaseKit
    - TuyaSmartBLEKit
    - TuyaSmartBLEMeshKit
    - TuyaSmartDeviceKit
    - TuyaSmartFeedbackKit
    - TuyaSmartHomeKit
    - TuyaSmartMessageKit
    - TuyaSmartMQTTChannelKit
    - TuyaSmartSceneKit
    - TuyaSmartSocketChannelKit
    - TuyaSmartTimerKit
    - TuyaSmartUtil
    - TYBluetooth
    - YYModel
  "https://<private>@bitbucket.org/<private>/cocoapods-repo.git":
    - COAnalytics
    - COAsynchronous
    - COCommons
    - COJSON
    - COKissXML

SPEC CHECKSUMS:
  AFNetworking: 8e4e60500beb8bec644cf575beee72990a76d399
  Bolts: ac6567323eac61e203f6a9763667d0f711be34c8
  COAnalytics: 909c9914c7e314e2347afa99cc50e27c0fb56ba7
  COAsynchronous: 347901f980dca0049a140c762c9c56af0a6d8c89
  CocoaAsyncSocket: eafaa68a7e0ec99ead0a7b35015e0bf25d2c8987
  COCommons: a939ff3535cbf25a4c4d482f61e5f74612171e3a
  COJSON: 4d6c5ef7eed1c02c0ab6b8368ddd2744aec11154
  COKissXML: 10d1fdbd5ee59f8a74615055e962bed12c12e2dc
  GoogleAnalytics: f42cc53a87a51fe94334821868d9c8481ff47a7b
  HockeySDK: 38b7e2726af1ea86ae97ce4b5de33ab0817e3500
  MBProgressHUD: 1569cf7ace17a8bac47aabfbb8580a49690386d1
  MQTTClient: eea2eaaa6ddef852a1019a4dda091e22ad928b58
  OpenSSL-Universal: ff04c2e6befc3f1247ae039e60c93f76345b3b5a
  Parse: 3b31a3dd1777b07ee7f0caee32fafbff544483a5
  Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
  TuyaSmartActivatorKit: ee0257b278f10f664579b12b390d2660380baadc
  TuyaSmartBaseKit: 484fbadfeee85816159e6710dfdaf54832e16a63
  TuyaSmartBLEKit: 550566b9dc2261e68f7a1cc1f48af64d128922cb
  TuyaSmartBLEMeshKit: 050e31c376a232dfbcab86bc39dc181a9041703e
  TuyaSmartDeviceKit: 078336c94cca94ce4a3ad4e6a6d70fe25afd862d
  TuyaSmartFeedbackKit: f847e9c8f19c9cb561e4e11bb1bc0f515ba5b11a
  TuyaSmartHomeKit: 085b5aa8020817ad8b8d13ba739fbd3ecd4c1ad5
  TuyaSmartMessageKit: e732a8e2f8cc8e3d3d5edf2ad9c269c245371d23
  TuyaSmartMQTTChannelKit: ec72a79d1da4c5c7706056159d42a2ebb128e364
  TuyaSmartSceneKit: fcc1122c9354fad2e2d68a7670b8cba76654304f
  TuyaSmartSocketChannelKit: 591e4d3e56b3e580f35603d99e6105d8bd00f78c
  TuyaSmartTimerKit: 3296a4e8ab503f6f6e84849591cfc3492c28a5ed
  TuyaSmartUtil: d63d20fe41bff8abc5b1f6bfe2227532b20c6a8f
  TYBluetooth: 6ba20f07b23d0ab2bc6d36b2d866b6c8df02c091
  YYModel: 2a7fdd96aaa4b86a824e26d0c517de8928c04b30

PODFILE CHECKSUM: f9db94d68532ab17e71e2cf6da432da69c480132

COCOAPODS: 1.7.5

Thanks!

TuyaRonbin commented 4 years ago

There is no problem with the version of CocoaAsyncSocket. Is this crash necessary or occasional? If not, what's the probability?

Paco480 commented 4 years ago

It always crashes when there is a paired device.

TuyaRonbin commented 4 years ago

Can provide me with a complete Console logs ? I have no idea now.

MimikFc7 commented 4 years ago

Hi maybe you can make simple variation with only pod tuya init?

Paco480 commented 4 years ago

Can provide me with a complete Console logs ? I have no idea now.

It works when running in a different wifi than the device and it also works in the simulator.

I will attach more detailed logs shortly, thank you.

Paco480 commented 4 years ago

These are Xcode console logs with [[TuyaSmartSDK sharedInstance] setDebugMode:YES]; are these the logs you need? how can I provide you with more detailed logs?

Tuya-Error-EXC_BAD_ACCESS-GCDAsyncSocket-doReadData-2.txt

Thanks

TuyaRonbin commented 4 years ago

Crash happens in CocoaAsyncSocket. We see that you have asked questions in the work order system, and we will reply your questions in the work order system. I will close this issue.

Paco480 commented 4 years ago

These are GCDAsyncSocket logs before crashing

2020-01-07 10:30:54.119392+0100 tuyatest[658:28412] GCDAsyncSocket: connectToHost:onPort:viaInterface:withTimeout:error:
2020-01-07 10:30:54.119584+0100 tuyatest[658:28412] GCDAsyncSocket: Dispatching DNS lookup...
2020-01-07 10:30:54.119915+0100 tuyatest[658:28319] GCDAsyncSocket: lookupHost:port:error:
2020-01-07 10:30:54.121406+0100 tuyatest[658:28342] GCDAsyncSocket: lookup:didSucceedWithAddress4:address6:
2020-01-07 10:30:54.121618+0100 tuyatest[658:28342] GCDAsyncSocket: connectWithAddress4:address6:error:
2020-01-07 10:30:54.121872+0100 tuyatest[658:28342] GCDAsyncSocket: IPv4: 192.168.5.112:6668
2020-01-07 10:30:54.122084+0100 tuyatest[658:28342] GCDAsyncSocket: IPv6: (null):0
2020-01-07 10:30:54.122328+0100 tuyatest[658:28342] GCDAsyncSocket: Creating IPv4 socket
2020-01-07 10:30:54.122651+0100 tuyatest[658:28342] GCDAsyncSocket: Connecting...
2020-01-07 10:30:54.197127+0100 tuyatest[658:28412] GCDAsyncSocket: didConnect:
2020-01-07 10:30:54.197705+0100 tuyatest[658:28412] GCDAsyncSocket: endConnectTimeout
2020-01-07 10:30:54.198089+0100 tuyatest[658:28412] GCDAsyncSocket: createReadAndWriteStream
2020-01-07 10:30:54.198251+0100 tuyatest[658:28412] GCDAsyncSocket: Creating read and write stream...
2020-01-07 10:30:54.198548+0100 tuyatest[658:28412] GCDAsyncSocket: registerForStreamCallbacksIncludingReadWrite: NO
2020-01-07 10:30:54.198867+0100 tuyatest[658:28412] GCDAsyncSocket: dispatch_resume(readSource)
2020-01-07 10:30:54.199065+0100 tuyatest[658:28412] GCDAsyncSocket: maybeDequeueRead
2020-01-07 10:30:54.199308+0100 tuyatest[658:28412] GCDAsyncSocket: maybeDequeueWrite
2020-01-07 10:30:54.200334+0100 tuyatest[658:28412] GCDAsyncSocket: readDataWithTimeout:buffer:bufferOffset:maxLength:tag:
2020-01-07 10:30:54.200657+0100 tuyatest[658:28412] GCDAsyncSocket: maybeDequeueRead
2020-01-07 10:30:54.200864+0100 tuyatest[658:28412] GCDAsyncSocket: Dequeued GCDAsyncReadPacket
2020-01-07 10:30:54.201006+0100 tuyatest[658:28412] GCDAsyncSocket: doReadData
2020-01-07 10:30:54.201213+0100 tuyatest[658:28412] GCDAsyncSocket: No data available to read...
2020-01-07 10:30:54.201470+0100 tuyatest[658:28412] GCDAsyncSocket: writeData:withTimeout:tag:
2020-01-07 10:30:54.201719+0100 tuyatest[658:28412] GCDAsyncSocket: maybeDequeueWrite
2020-01-07 10:30:54.202291+0100 tuyatest[658:28412] GCDAsyncSocket: Dequeued GCDAsyncWritePacket
2020-01-07 10:30:54.202467+0100 tuyatest[658:28412] GCDAsyncSocket: doWriteData
2020-01-07 10:30:54.202939+0100 tuyatest[658:28412] GCDAsyncSocket: wrote to socket = 86
2020-01-07 10:30:54.203224+0100 tuyatest[658:28412] GCDAsyncSocket: currentWrite->bytesDone = 86
2020-01-07 10:30:54.203578+0100 tuyatest[658:28412] GCDAsyncSocket: completeCurrentWrite
2020-01-07 10:30:54.203883+0100 tuyatest[658:28412] GCDAsyncSocket: addStreamsToRunLoop
2020-01-07 10:30:54.204035+0100 tuyatest[658:28412] GCDAsyncSocket: Adding streams to runloop...
2020-01-07 10:30:54.204273+0100 tuyatest[658:28412] GCDAsyncSocket: startCFStreamThreadIfNeeded
2020-01-07 10:30:54.204783+0100 tuyatest[658:28412] GCDAsyncSocket: CFStreamThread: Started
2020-01-07 10:30:54.205047+0100 tuyatest[658:28412] GCDAsyncSocket: scheduleCFStreams:
2020-01-07 10:30:54.205378+0100 tuyatest[658:28412] GCDAsyncSocket: openStreams
2020-01-07 10:30:54.205532+0100 tuyatest[658:28412] GCDAsyncSocket: Opening read and write stream...
2020-01-07 10:30:54.206103+0100 tuyatest[658:28324] GCDAsyncSocket: maybeDequeueWrite
2020-01-07 10:30:54.244573+0100 tuyatest[658:28412] GCDAsyncSocket: readEventBlock
2020-01-07 10:30:54.244918+0100 tuyatest[658:28412] GCDAsyncSocket: socketFDBytesAvailable: 181
2020-01-07 10:30:54.245334+0100 tuyatest[658:28412] GCDAsyncSocket: readEventBlock
2020-01-07 10:30:54.245643+0100 tuyatest[658:28412] GCDAsyncSocket: socketFDBytesAvailable: 181
2020-01-07 10:30:54.245996+0100 tuyatest[658:28412] GCDAsyncSocket: readEventBlock
2020-01-07 10:30:54.246260+0100 tuyatest[658:28412] GCDAsyncSocket: socketFDBytesAvailable: 181
2020-01-07 10:30:54.246886+0100 tuyatest[658:28412] GCDAsyncSocket: readEventBlock
2020-01-07 10:30:54.247328+0100 tuyatest[658:28412] GCDAsyncSocket: socketFDBytesAvailable: 181
2020-01-07 10:30:54.247742+0100 tuyatest[658:28412] GCDAsyncSocket: doReadData
2020-01-07 10:30:54.247902+0100 tuyatest[658:28412] GCDAsyncSocket: readEventBlock
2020-01-07 10:30:54.248069+0100 tuyatest[658:28412] GCDAsyncSocket: Reading 181 bytes

We solved this issue by changing line 5264 from GCDAsyncSocket.m as shown below

            ssize_t result = 1; //read(socketFD, buffer, (size_t)bytesToRead);

all the humidifier controls seem to be working

can you confirm if this is OK?

thank you!

TuyaRonbin commented 4 years ago

Do you integrate GCDAsyncSocket via pod?Or manual integration?

Paco480 commented 4 years ago

We integrate pod "TuyaSmartHomeKit" (GCDAsyncSocket is a Tuya SDK dependency), then we unlock CocoaAsyncSocket in Xcode so we can modify the line that crashes.

Is it OK?

Thanks

TuyaRonbin commented 4 years ago

I haven't encountered any crash in the source code of GCDAsyncSocket in development. You can try to modify it.