Skip to content

Conversation

@ncooke3
Copy link
Member

@ncooke3 ncooke3 commented Dec 9, 2025

Tip: Ignore whitespace when reviewing – https://github.com/firebase/firebase-ios-sdk/pull/15583/files?w=1

This PR addresses one source of flaky tests in the Crashlytics test suite.

Problem: A race condition occurred where FIRCLSBinaryImageInit zero-initialized the global context while a background thread from a previous test was still cleaning up. This caused a valid file descriptor to be overwritten with 0 (stdin). Attempting to close(0) triggers the operating system's EXC_GUARD protection, killing the process.

Solution: Patched FIRCLSFileClose to strictly ignore file descriptors <= STDERR_FILENO (0, 1, 2). This ensures the SDK never accidentally closes standard input/output streams, even if the file structure is improperly initialized to zero.

Process

  1. Repro locally (may take a few attempts)
xcodebuild \                                                 
  -scheme FirebaseCrashlyticsUnit \
  -destination "platform=iOS Simulator,name=iPhone 16e" \
  ONLY_ACTIVE_ARCH=YES \
  CODE_SIGNING_REQUIRED=NO \
  CODE_SIGNING_ALLOWED=YES \
  COMPILER_INDEX_STORE_ENABLE=NO \
  CC=clang \
  CPLUSPLUS=clang++ \
  LD=clang \
  LDPLUSPLUS=clang++ \
  IPHONEOS_DEPLOYMENT_TARGET=13.0 \
  TVOS_DEPLOYMENT_TARGET=13.0 \
  clean test
  1. I saw this suspicious message.
Test Case '-[FIRCLSSettingsTests testActivatedSettingsMissingCacheKey]' started.

Restarting after unexpected exit, crash, or test timeout; summary will include totals from previous launches.
  1. At the bottom of the test session logs was:
Test session results, code coverage, and logs:

/Users/nickcooke/Library/Developer/Xcode/DerivedData/firebase-ios-sdk-anxqgakbhyqozfhbkutiwmcpphvm/Logs/Test/Test-FirebaseCrashlyticsUnit-2025.12.09_14-59-50--0500.xcresult
  1. Open the xcresult in Xcode by running open <xcresult path> on command line.
  2. The crash was due to the file close method in Crashlytics (right click to see full trace).
Screenshot 2025-12-09 at 5 12 57 PM

Manual Testing

I ran 10 invocations of the test command for each of the following cases.

  • Without fix: 40% flake rate (each flake was a different test)
  • With fix: 0% flake rate 🎉

#no-changelog

@gemini-code-assist
Copy link
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

Customization

To customize 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 counter productive. 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.

@ncooke3
Copy link
Member Author

ncooke3 commented Dec 9, 2025

re: CI– Unfortunately, it isn't a cure-all, but I think it's progress, considering the positive local testing.

@ncooke3 ncooke3 requested a review from paulb777 December 9, 2025 22:48
@paulb777
Copy link
Member

paulb777 commented Dec 9, 2025

Nice find!

@ncooke3 ncooke3 merged commit 04a2b57 into main Dec 9, 2025
49 of 51 checks passed
@ncooke3 ncooke3 deleted the nc/csh-flakes branch December 9, 2025 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants