Skip to content

[Crashlytics] Fix deadlock in user logging on reentrant queue access. (#16163)#16192

Open
JesusRojass wants to merge 7 commits into
firebase:mainfrom
JesusRojass:JesusRojass/#16163
Open

[Crashlytics] Fix deadlock in user logging on reentrant queue access. (#16163)#16192
JesusRojass wants to merge 7 commits into
firebase:mainfrom
JesusRojass:JesusRojass/#16163

Conversation

@JesusRojass
Copy link
Copy Markdown
Member

Discussion

This PR resolves the deadlock in the Crashlytics serial logging queue. When a thread already executing on _firclsLoggingQueue makes 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 using dispatch_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.

@JesusRojass JesusRojass requested review from mghaznav and tejasd May 20, 2026 20:16
@JesusRojass JesusRojass self-assigned this May 20, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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.

@JesusRojass
Copy link
Copy Markdown
Member Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread Crashlytics/Crashlytics/Components/FIRCLSContext.m
@JesusRojass
Copy link
Copy Markdown
Member Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread Crashlytics/Crashlytics/Components/FIRCLSContext.m Outdated
@JesusRojass
Copy link
Copy Markdown
Member Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread Crashlytics/Crashlytics/Components/FIRCLSContext.m Outdated
@JesusRojass
Copy link
Copy Markdown
Member Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread Crashlytics/Crashlytics/Components/FIRCLSContext.m Outdated
@JesusRojass
Copy link
Copy Markdown
Member Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread Crashlytics/Crashlytics/Components/FIRCLSContext.m Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deadlock in FIRCLSUserLoggingWriteAndCheckABFiles

1 participant