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

Crash in AWSIoTMQTTClient.m line 635 -[AWSIoTMQTTClient openStreams:] #1209

Closed miralshahvolansys closed 3 years ago

miralshahvolansys commented 5 years ago

Description Recently we have received a lot of crash logs regarding this, and the code that caused the crash is pointing to AWSIoTMQTTClient.m line 635 -[AWSIoTMQTTClient openStreams:].

We have used AWS SDK version '2.7.3' It is not reproducible, Based on Fabric logs, we found that in last 30days we have 21 crash logs

Environment

Device Information

Fabric crash logs

0. com.apple.uikit.eventfetch-thread

0 libsystem_kernel.dylib 0x1879abea4 mach_msg_trap + 8 1 libsystem_kernel.dylib 0x1879ab37c mach_msg + 72 2 CoreFoundation 0x187db0be8 CFRunLoopServiceMachPort + 236 3 CoreFoundation 0x187daba84 CFRunLoopRun + 1396 4 CoreFoundation 0x187dab1f0 CFRunLoopRunSpecific + 436 5 Foundation 0x1887a1494 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 300 6 Foundation 0x1887a1340 -[NSRunLoop(NSRunLoop) runUntilDate:] + 148 7 UIKitCore 0x1b50a71f4 -[UIEventFetcher threadMain] + 136 8 Foundation 0x1888d423c NSThreadstart__ + 1040 9 libsystem_pthread.dylib 0x187a3c25c _pthread_body + 128 10 libsystem_pthread.dylib 0x187a3c1bc _pthread_start + 48 11 libsystem_pthread.dylib 0x187a3fcf4 thread_start + 4

1. GAIThread

0 libsystem_kernel.dylib 0x1879abea4 mach_msg_trap + 8 1 libsystem_kernel.dylib 0x1879ab37c mach_msg + 72 2 CoreFoundation 0x187db0be8 CFRunLoopServiceMachPort + 236 3 CoreFoundation 0x187daba84 CFRunLoopRun + 1396 4 CoreFoundation 0x187dab1f0 CFRunLoopRunSpecific + 436 5 Foundation 0x1887a1494 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 300 6 Foundation 0x1887dce84 -[NSRunLoop(NSRunLoop) run] + 88 7 OneLinkHome 0x1023c56b8 +[GAI threadMain:] + 4348319416 8 Foundation 0x1888d423c NSThreadstart__ + 1040 9 libsystem_pthread.dylib 0x187a3c25c _pthread_body + 128 10 libsystem_pthread.dylib 0x187a3c1bc _pthread_start + 48 11 libsystem_pthread.dylib 0x187a3fcf4 thread_start + 4

2. Thread

0 libsystem_kernel.dylib 0x1879abea4 mach_msg_trap + 8 1 libsystem_kernel.dylib 0x1879ab37c mach_msg + 72 2 CoreFoundation 0x187db0be8 CFRunLoopServiceMachPort + 236 3 CoreFoundation 0x187daba84 CFRunLoopRun + 1396 4 CoreFoundation 0x187dab1f0 CFRunLoopRunSpecific + 436 5 Foundation 0x1887a1494 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 300 6 HomeKit 0x1a02fdfe8 -[_HMLocationHandler createLocationManager] + 496 7 Foundation 0x1888d423c NSThreadstart__ + 1040 8 libsystem_pthread.dylib 0x187a3c25c _pthread_body + 128 9 libsystem_pthread.dylib 0x187a3c1bc _pthread_start + 48 10 libsystem_pthread.dylib 0x187a3fcf4 thread_start + 4

3. Thread

0 libsystem_kernel.dylib 0x1879abea4 mach_msg_trap + 8 1 libsystem_kernel.dylib 0x1879ab37c mach_msg + 72 2 CoreFoundation 0x187db0be8 CFRunLoopServiceMachPort + 236 3 CoreFoundation 0x187daba84 CFRunLoopRun + 1396 4 CoreFoundation 0x187dab1f0 CFRunLoopRunSpecific + 436 5 Foundation 0x1887a1494 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 300 6 AWSIoT 0x102e6a0a8 -[AWSIoTMQTTClient openStreams:] (AWSIoTMQTTClient.m:635) 7 Foundation 0x1888d423c NSThreadstart__ + 1040 8 libsystem_pthread.dylib 0x187a3c25c _pthread_body + 128 9 libsystem_pthread.dylib 0x187a3c1bc _pthread_start + 48 10 libsystem_pthread.dylib 0x187a3fcf4 thread_start + 4

4. com.apple.NSURLConnectionLoader

0 libsystem_kernel.dylib 0x1879abea4 mach_msg_trap + 8 1 libsystem_kernel.dylib 0x1879ab37c mach_msg + 72 2 CoreFoundation 0x187db0be8 CFRunLoopServiceMachPort + 236 3 CoreFoundation 0x187daba84 CFRunLoopRun + 1396 4 CoreFoundation 0x187dab1f0 CFRunLoopRunSpecific + 436 5 CFNetwork 0x1883ce00c -[CoreSchedulingSetRunnable runForever] + 212 6 Foundation 0x1888d423c NSThreadstart + 1040 7 libsystem_pthread.dylib 0x187a3c25c _pthread_body + 128 8 libsystem_pthread.dylib 0x187a3c1bc _pthread_start + 48 9 libsystem_pthread.dylib 0x187a3fcf4 thread_start + 4

5. com.apple.CFSocket.private

0 libsystem_kernel.dylib 0x1879b7350 select + 8 1 CoreFoundation 0x187db9a38 CFSocketManager + 620 2 libsystem_pthread.dylib 0x187a3c25c _pthread_body + 128 3 libsystem_pthread.dylib 0x187a3c1bc _pthread_start + 48 4 libsystem_pthread.dylib 0x187a3fcf4 thread_start + 4

6. com.twitter.crashlytics.ios.MachExceptionServer

0 OneLinkHome 0x10251ed14 CLSProcessRecordAllThreads + 4349734164 1 OneLinkHome 0x10251ed14 CLSProcessRecordAllThreads + 4349734164 2 OneLinkHome 0x10251ebd0 CLSProcessRecordAllThreads + 4349733840 3 OneLinkHome 0x10250e0c0 CLSHandler + 4349665472 4 OneLinkHome 0x1025090d4 CLSMachExceptionServer + 4349645012 5 libsystem_pthread.dylib 0x187a3c25c _pthread_body + 128 6 libsystem_pthread.dylib 0x187a3c1bc _pthread_start + 48 7 libsystem_pthread.dylib 0x187a3fcf4 thread_start + 4

7. Thread

0 libsystem_kernel.dylib 0x1879b7b9c __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x187a3d100 _pthread_wqthread + 348 2 libsystem_pthread.dylib 0x187a3fcec start_wqthread + 4

8. JavaScriptCore bmalloc scavenger

0 libsystem_kernel.dylib 0x1879b6f0c psynch_cvwait + 8 1 libsystem_pthread.dylib 0x187a34c88 _pthread_cond_wait$VARIANT$mp + 636 2 libc++.1.dylib 0x186f844d0 std::__1::condition_variable::wait(std::1::unique_lock&) + 24 3 JavaScriptCore 0x18f1629c8 void std::1::condition_variable_any::wait<std::1::unique_lock >(std::1::unique_lock&) + 104 4 JavaScriptCore 0x18f166abc bmalloc::Scavenger::threadRunLoop() + 176 5 JavaScriptCore 0x18f1661f0 bmalloc::Scavenger::Scavenger(std::__1::lock_guard&) + 10 6 JavaScriptCore 0x18f167c9c std::1::thread_specific_ptr<std::1::thread_struct>::set_pointer(std::1::__thread_struct*) + 38 7 libsystem_pthread.dylib 0x187a3c25c _pthread_body + 128 8 libsystem_pthread.dylib 0x187a3c1bc _pthread_start + 48 9 libsystem_pthread.dylib 0x187a3fcf4 thread_start + 4

9. WebThread

0 libsystem_kernel.dylib 0x1879abea4 mach_msg_trap + 8 1 libsystem_kernel.dylib 0x1879ab37c mach_msg + 72 2 CoreFoundation 0x187db0be8 CFRunLoopServiceMachPort + 236 3 CoreFoundation 0x187daba84 CFRunLoopRun + 1396 4 CoreFoundation 0x187dab1f0 CFRunLoopRunSpecific + 436 5 WebCore 0x190c1aeec RunWebThread(void*) + 592 6 libsystem_pthread.dylib 0x187a3c25c _pthread_body + 128 7 libsystem_pthread.dylib 0x187a3c1bc _pthread_start + 48 8 libsystem_pthread.dylib 0x187a3fcf4 thread_start + 4

10. Thread

0 libsystem_kernel.dylib 0x1879b7b9c __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x187a3d1c0 _pthread_wqthread + 540 2 libsystem_pthread.dylib 0x187a3fcec start_wqthread + 4

11. Thread

0 libsystem_kernel.dylib 0x1879b7b9c __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x187a3d100 _pthread_wqthread + 348 2 libsystem_pthread.dylib 0x187a3fcec start_wqthread + 4

12. com.apple.WAC.workQueue

0 libsystem_kernel.dylib 0x1879abee0 semaphore_wait_trap + 8 1 libdispatch.dylib 0x1877faf7c _dispatch_sema4_wait$VARIANT$mp + 24 2 libdispatch.dylib 0x1877fba00 _dispatch_semaphore_wait_slow + 136 3 libdispatch.dylib 0x1878596c8 _dispatch_call_block_and_release + 24 4 libdispatch.dylib 0x18785a484 _dispatch_client_callout + 16 5 libdispatch.dylib 0x187801bd0 _dispatch_lane_serial_drain$VARIANT$mp + 592 6 libdispatch.dylib 0x187802718 _dispatch_lane_invoke$VARIANT$mp + 432 7 libdispatch.dylib 0x18780aeb8 _dispatch_workloop_worker_thread + 600 8 libsystem_pthread.dylib 0x187a3d0dc _pthread_wqthread + 312 9 libsystem_pthread.dylib 0x187a3fcec start_wqthread + 4

13. Thread

0 libsystem_pthread.dylib 0x187a3fce8 start_wqthread + 190

mutablealligator commented 5 years ago

@miralshahvolansys Sorry for the inconvenience caused. Can you past a code snippet and describe the use case you are trying to accomplish? What is the authentication mechanism you are trying to use while connecting with AWS IoT?

miralshahvolansys commented 5 years ago

Code snippet:

- (void)openStreams:(id)sender
{
    //This is invoked in a new thread by the webSocketDidOpen method or by the Connect method. Get the runLoop from the thread.
    NSRunLoop *runLoopForStreamsThread = [NSRunLoop currentRunLoop];

    //Setup a default timer to ensure that the RunLoop always has atleast one timer on it. This is to prevent the while loop
    //below to spin in tight loop when all input sources and session timers are shutdown during a reconnect sequence.
    NSTimer *defaultRunLoopTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:60.0]
                                                            interval:60.0
                                                              target:self
                                                            selector:@selector(timerHandler:)
                                                            userInfo:nil
                                                             repeats:YES];
    [runLoopForStreamsThread addTimer:defaultRunLoopTimer forMode:NSDefaultRunLoopMode];

    self.runLoopShouldContinue = YES;
    [self.toDecoderStream scheduleInRunLoop:runLoopForStreamsThread forMode:NSDefaultRunLoopMode];
    [self.toDecoderStream open];

    //Update the runLoop and runLoopMode in session.
    [self.session connectToInputStream:self.decoderStream outputStream:self.encoderStream];

    while (self.runLoopShouldContinue && NSThread.currentThread.isCancelled == NO) {
        //This will continue run until runLoopShouldContinue is set to NO during "disconnect" or
        //"websocketDidFail"

        //Run one cycle of the runloop. This will return after a input source event or timer event is processed
        [runLoopForStreamsThread runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:10]];
    }

    // clean up the defaultRunLoopTimer.
    [defaultRunLoopTimer invalidate];

    if (!self.runLoopShouldContinue ) {
        [self.session close];

        //Set status
        self.mqttStatus = AWSIoTMQTTStatusDisconnected;

        // Let the client know it has been disconnected.
        [self notifyConnectionStatus];
    }
}

As per the crashalytics, we are getting crash in below line,

[runLoopForStreamsThread runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:10]];

Question: What is the authentication mechanism you are trying to use while connecting with AWS IoT? Ans: AWS Cognito

docee commented 5 years ago

We had the same problem. @cbommas

bhavinmdesai commented 5 years ago

We're also affected with this issue and using AWS Cognito to connect with AWS IoT.

SDK Version: 2.6.34

miralshahvolansys commented 5 years ago

@cbommas any update on this?

Tykhonkov commented 5 years ago

Guys any update on this?

vtniteshgunani commented 5 years ago

Any update on this issue?

palpatim commented 5 years ago

We have done some cleanup in the MQTT client over the intervening releases since this issue was reported. Is this still occurring on the latest release (2.10.0)?

bhavinmdesai commented 5 years ago

@palpatim I will upgrade the SDK and give it a go.

vtniteshgunani commented 5 years ago

I am still facing this issue in 2.10.0, please provide solution on urgent bases.

SebOvs commented 4 years ago

we had the same problem in 2.13.0 Any update on this issue?

palpatim commented 4 years ago

Should be addressed at least partially by https://github.com/aws-amplify/aws-sdk-ios/pull/2949, scheduled to go out in 2.15.2.

palpatim commented 3 years ago

I'm going to close this old issue since we (@wooj2 in particular) has made a number of fixes to the IoT SDK to clean up stream and connection handling. If anybody finds a similar problem in future, open a new issue and feel free to reference this issue in your description.