Closed wxsdmy closed 5 years ago
I am also having similar kind of exception for my live app users. It has happened sometime to our internal test users as well but we don't have exact steps to reproduce. Here is my stacktrace:
Fatal Exception: NSRangeException
0 CoreFoundation 0x1d1a0fef8 __exceptionPreprocess
1 libobjc.A.dylib 0x1d0bdda40 objc_exception_throw
2 CoreFoundation 0x1d198585c _CFArgv
3 CoreFoundation 0x1d18f5ba8 -[__NSArrayM objectAtIndex:]
4 Rewardle 0x10319c4ec -[AWSMQTTSession drainSenderQueue] (AWSMQTTSession.m:672)
5 Rewardle 0x10319bfdc -[AWSMQTTSession send:] (AWSMQTTSession.m:646)
6 Rewardle 0x103198f28 -[AWSMQTTSession subscribeToTopic:atLevel:] (AWSMQTTSession.m:167)
7 Rewardle 0x1031800dc -[AWSIoTMQTTClient subscribeToTopic:qos:messageCallback:ackCallback:] (AWSIoTMQTTClient.m:767)
8 Rewardle 0x10317fe78 -[AWSIoTMQTTClient subscribeToTopic:qos:messageCallback:] (AWSIoTMQTTClient.m:741)
9 Rewardle 0x1031520f0 -[AWSIoTDataManager subscribeToTopic:QoS:messageCallback:] (AWSIoTDataManager.m:528)
10 Rewardle 0x10300d424 -[RealTimeFeedCall subscriptionCall] (RealTimeFeedCall.m:194)
11 Rewardle 0x10317f01c __42-[AWSIoTMQTTClient notifyConnectionStatus]_block_invoke (AWSIoTMQTTClient.m:580)
12 libdispatch.dylib 0x1d14476c8 _dispatch_call_block_and_release
13 libdispatch.dylib 0x1d1448484 _dispatch_client_callout
14 libdispatch.dylib 0x1d13f7b94 _dispatch_root_queue_drain
15 libdispatch.dylib 0x1d13f8308 _dispatch_worker_thread2
16 libsystem_pthread.dylib 0x1d162a190 _pthread_wqthread
17 libsystem_pthread.dylib 0x1d162cd00 start_wqthread
Hi @wxsdmy @bhavinmdesai
Looking at the drainSenderQueue implementation, https://github.com/aws/aws-sdk-ios/blob/master/AWSIoT/Internal/MQTTSDK/AWSM... we remove the object from the queue until the queue is empty. I see two callers to this method 1) sending a message 2) the timer handler. In addition to this the encoder dequeues the element at the front of the queue: "- (void)encoder:(AWSMQTTEncoder*)sender handleEvent:(AWSMQTTEncoderEvent) eventCode" when the mqtt connection is established in order to encode the message. It is possible that there is a race between these three potential callers which try to mutate the queue without proper synchronization. Continuing my root-cause.
Would it be possible to share a sample app or code snippet where you use the IoT SDK?
@wxsdmy @bhavinmdesai
The latest rev of the iOS SDK (2.6.34) contains a fix for this issue. Can you update to the latest rev and let us know how it goes?
@wxsdmy @bhavinmdesai
Closing this issue as I haven't heard back. Please feel free to reopen if the error is still occurring.
2018/10/24 12:22:39:926 -------- Exception -------- reson: NSRangeException Exception name:*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array Exception stack:( 0 CoreFoundation 0x0000000184727f10 + 252
1 libobjc.A.dylib 0x00000001838f5a40 objc_exception_throw + 56
2 CoreFoundation 0x000000018469d85c _CFArgv + 0
3 CoreFoundation 0x000000018460dba8 + 188
4 AWSIoT 0x0000000102780d78 -[AWSMQTTSession drainSenderQueue] + 372
5 AWSIoT 0x0000000102780868 -[AWSMQTTSession send:] + 100
6 AWSIoT 0x000000010277d7b4 -[AWSMQTTSession subscribeToTopic:atLevel:] + 264
7 AWSIoT 0x000000010277a77c -[AWSIoTMQTTClient session:handleEvent:] + 948
8 AWSIoT 0x000000010277efe4 -[AWSMQTTSession decoder:newMessage:] + 1172
9 AWSIoT 0x00000001027c44b0 -[AWSMQTTDecoder stream:handleEvent:] + 1428
10 CoreFoundation 0x00000001846c941c + 216
11 CoreFoundation 0x00000001846c8a08 + 372
12 CoreFoundation 0x00000001846b65b8 + 24
13 CoreFoundation 0x00000001846b6538 + 88
14 CoreFoundation 0x00000001846b5e1c + 176
15 CoreFoundation 0x00000001846b0ce8 + 1040
16 CoreFoundation 0x00000001846b05b8 CFRunLoopRunSpecific + 436
17 Foundation 0x00000001850a46a4 + 300
18 AWSIoT 0x0000000102778ef8 -[AWSIoTMQTTClient openStreams:] + 676
19 Foundation 0x00000001851d73b0 + 1040
20 libsystem_pthread.dylib 0x00000001843412fc + 128
21 libsystem_pthread.dylib 0x000000018434125c _pthread_start + 48
22 libsystem_pthread.dylib 0x0000000184344d08 thread_start + 4
)
SDK Version: 2.6.32