[Crashlytics] Fix deadlock in user logging on reentrant queue access. (#16163)#16192
[Crashlytics] Fix deadlock in user logging on reentrant queue access. (#16163)#16192JesusRojass wants to merge 7 commits into
Conversation
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a utility function FIRCLSExecuteOnLoggingQueue to prevent potential deadlocks by checking if the current execution is already on the logging queue before performing a synchronous dispatch. The reviewer suggested adding defensive null checks for the block and the queue within this new function to improve robustness and prevent crashes in critical paths.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a helper function, FIRCLSExecuteOnLoggingQueue, to manage thread-safe execution on the logging queue, replacing direct dispatch_sync calls to prevent potential deadlocks. The implementation correctly sets queue-specific data to track the logging queue. A review comment suggests adding a null check for _firclsLoggingQueue before setting queue-specific data to enhance robustness.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new helper function, FIRCLSExecuteOnLoggingQueue, designed to prevent deadlocks by checking for reentrancy on the logging queue before performing a synchronous dispatch. The changes include setting queue-specific data during initialization and updating logging calls to use this new utility. A review comment identifies a potential issue where blocks are silently dropped if the logging queue fails to initialize, suggesting a fallback mechanism or explicit handling for that scenario.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces the FIRCLSExecuteOnLoggingQueue utility to safely execute blocks on the logging queue, preventing potential deadlocks by checking if the current execution context is already on that queue. The changes include initializing the logging queue with a specific key and updating FIRCLSUserLogging.m to utilize this new helper function. Review feedback suggests reordering the logic within FIRCLSExecuteOnLoggingQueue to check for the queue's existence before its specific context to improve readability and clarify the intent of the safety fallback.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to prevent deadlocks on the Crashlytics logging queue by implementing a reentrancy check. It adds a helper function, FIRCLSExecuteOnLoggingQueue, which uses dispatch_get_specific to determine if a block can be executed immediately or requires a synchronous dispatch. Feedback suggests adding diagnostic logging when the logging queue is null to prevent masking potential initialization issues.
Discussion
This PR resolves the deadlock in the Crashlytics serial logging queue. When a thread already executing on
_firclsLoggingQueuemakes a call to log or write keys and values, the synchronous dispatch blocks the thread and deadlocks the serial queue.By introducing a queue-specific key with
dispatch_queue_set_specific, we can check the executing context usingdispatch_get_specific. If the current thread is already running on the logging queue, the block executes directly to preserve order without deadlocking.Fixes #16163
Testing
The change has been reviewed locally and formatted with
scripts/style.sh. The Crashlytics unit test suite will be run in Xcode prior to merge.API Changes
This change is strictly internal. There are no public API modifications.