-
Notifications
You must be signed in to change notification settings - Fork 885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash report in [AWSIoTStreamThread .cxx_destruct] #5452
Comments
@tangguoEddy Are you able to provide more details about how to reproduce this crash on a local machine? |
Hey all, we are also facing same issue in prod. With no luck reproducing it locally. Risk: The AWSIoTStreamThread relies on manually managing its lifecycle with start, isRunning, and cancel states. Improper synchronization can lead to race conditions, especially when starting or canceling the thread. The isRunning flag is updated but not thread-safe, as it is accessed in both the main loop and external methods (cancel or cancelAndDisconnect). Risk: Cleanup operations (e.g., invalidating streams, closing resources) are distributed across cleanUp, cancel, and cancelAndDisconnect. This can lead to inconsistent behavior or resource leaks if these methods are called out of sequence. cleanUp depends on shouldDisconnect, which may not always be set consistently. A canceled thread may still execute cleanup logic if isRunning is not synchronized. Risk: The defaultRunLoopTimer is essential for maintaining the run loop's activity. If the timer is invalidated prematurely (e.g., in cleanUp or during reconnection), the run loop might exit unexpectedly. The timer is invalidated during cleanUp:
The run loop exits based on isRunning and isCancelled, but a missing timer could cause it to terminate prematurely. Since there are plenty of things that could potentially lead to the crash can you review this updated implementation?
The improvements ensure that: I'm not sure if it is critical to have properties |
Thanks for your input @AndrKonovalov ! Someone will take a look at your code and provide comments as soon as they have bandwidth |
…ws-amplify#5452 Related issue: aws-amplify#5452 Description of changes: 1. Addition of Synchronization Primitives New Properties: - dispatch_queue_t cleanupQueue - dispatch_semaphore_t cleanupSemaphore - BOOL isCleaningUp Purpose: Ensures thread-safe access and modification of critical properties like isRunning, shouldDisconnect, and defaultRunLoopTimer. Synchronization prevents race conditions during cleanup and cancellation processes. 2. Enhanced shouldContinueRunning Method Before: Used direct property access without synchronization After: Introduced synchronization using dispatch_sync for thread-safe checks Purpose:Prevents inconsistencies if multiple threads attempt to read/write properties simultaneously. 3. Cleanup Enhancements performCleanup and cleanupResources: Added explicit synchronization: dispatch_sync and dispatch_semaphore ensure cleanup operations are thread-safe and do not overlap if called multiple times. Handles complex cleanup sequences safely, such as invalidating timers, disconnecting streams, and deallocating the session. Purpose: Ensures that cleanup actions (e.g., closing streams and invalidating timers) are thread-safe and only executed once. 4. Timer Initialization Weak Reference to Prevent Retain Cycles: The timer in setupRunLoop now uses a __weak reference to avoid retain cycles Before: Used a strong reference (target:self), which could result in a retain cycle. Purpose: Avoids potential memory leaks by ensuring the thread does not retain itself via the timer. 5. Improved cancel Method Before: Simple isRunning flag and direct super cancel call After: Introduced thread-safe handling and ensured timer invalidation Purpose: Prevents race conditions when canceling the thread, ensuring timers are invalidated and properties are safely updated.
when i use AWSiOSSDKV2 2.37.2, I get this crash report。
I use IoT APIs like this
The text was updated successfully, but these errors were encountered: