aws-amplify / aws-sdk-ios

AWS SDK for iOS. For more information, see our web site:
https://aws-amplify.github.io/docs
Other
1.68k stars 885 forks source link

AWSIoTMQTTClient - Thread is not safe, causing reconnectThread to be start again. #1190

Closed docee closed 5 years ago

docee commented 5 years ago

Describe the bug Recently we have received a lot of NSThread crash logs, and the code that caused the crash is pointing to[self.reconnectThread start].

reconnectThread is called a total of five times in AWSIoTMQTTClient and can be called by multiple different threads simultaneously.

Exception Name:NSInvalidArgumentException Exception Time:2019-01-22 23:54:26 GMT Device Model:iPhone10,4 Network Type:Unknown System Version:12.1.2 APP Version:5.4.2(70599) Jailbreak:NO Exception Reason:*** -[NSThread start]: attempt to start the thread again Stack:{ UncaughtExceptionHandlerAddressesKey = ( 0 CoreFoundation 0x00000001e3c38edc + 252 1 libobjc.A.dylib 0x00000001e2e09a40 objc_exception_throw + 56 2 CoreFoundation 0x00000001e3b3f594 + 0 3 Foundation 0x00000001e45b6ba4 + 132 4 mynetvue 0x0000000100984c18 mynetvue + 2984984 5 mynetvue 0x00000001009a7e90 mynetvue + 3128976 6 libdispatch.dylib 0x00000001e36716c8 + 24 7 libdispatch.dylib 0x00000001e3672484 + 16 8 libdispatch.dylib 0x00000001e3654c14 + 640 9 libdispatch.dylib 0x00000001e365534c + 116 10 libsystem_pthread.dylib 0x00000001e385517c _pthread_wqthread + 472 11 libsystem_pthread.dylib 0x00000001e3857cec start_wqthread + 4 ); }

Which AWS service(s) are affected? IoT

Environment(please complete the following information):

Device Information (please complete the following information):

scb01 commented 5 years ago

@docee Sorry to hear that you are running into issues. I will take a look at this and get back to you

docee commented 5 years ago

@cbommas Any update?

scb01 commented 5 years ago

@docee I have a fix that I'm currently testing. I hope to get it included in the next release if all goes well. I will keep you updated on this thread.

docee commented 5 years ago

@cbommas

After we updated to 2.9.1, we found that the problem of Thread restart was solved, but it caused another crash.

The crash information is as follows:

Crashed: Thread 0 libobjc.A.dylib 0x1a1891430 objc_retain + 16 1 mynetvue 0x104e32640 -[AWSIoTMQTTClient initiateReconnectTimer:] (AWSIoTMQTTClient.m:697) 2 Foundation 0x1a315d23c NSThreadstart__ + 1040 3 libsystem_pthread.dylib 0x1a22c425c _pthread_body + 128 4 libsystem_pthread.dylib 0x1a22c41bc _pthread_start + 48 5 libsystem_pthread.dylib 0x1a22c7cf4 thread_start + 4

Download logs

frankmuellr commented 5 years ago

@docee, we released a fix. Please try out the latest SDK.

docee commented 5 years ago

@muellerfr Already solved. Very thanks.🙂