Skip to content

fix(storage): serialize auth and app check token updates - #16766

Open
dajiaohuang wants to merge 3 commits into
firebase:mainfrom
dajiaohuang:fix/storage-authorizer-token-update-serialization
Open

dajiaohuang wants to merge 3 commits into
firebase:mainfrom
dajiaohuang:fix/storage-authorizer-token-update-serialization

Conversation

@dajiaohuang

@dajiaohuang dajiaohuang commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Serialize Auth/App Check header updates on the existing serialAuthArgsQueue, preserving the public completion queue.
  • The concurrent mutation is reachable with custom interop providers or when an application changes the Promises default callback queue. Shipping Auth and App Check providers otherwise deliver callbacks on main.
  • Add parallel-provider regression coverage with bounded semaphore waits; update Unreleased changelog with fix(storage): serialize auth and app check token updates #16766.

Validation

  • Changed Swift files pass pinned SwiftFormat 0.55.5 lint and git diff --check.
  • Actual FirebaseStorageUnit/StorageAuthorizerTests on Xcode 26.4.1 and an iOS simulator: 17 tests passed, zero failures, including testAuthAndAppCheckTokenHeadersAreMutatedSerially, at source 76fbd7f.
  • Native XCTest run uses the repository Swift Package test setup. This is focused class coverage; the full platform matrix remains separate.

@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.

@Lzybear22

Copy link
Copy Markdown

I'm new to Swift. What was causing the issue with the request headers?

@paulb777

paulb777 commented Oct 1, 2026

Copy link
Copy Markdown
Member

Thanks for the contribution! A few housekeeping items:

  • CHANGELOG: The entry in FirebaseStorage/CHANGELOG.md is under # 12.19.0, which has already shipped. Please move it under a # Unreleased heading at the top of the file (add the heading if it isn't there yet).
  • PR number: end the entry with this PR's number, e.g. - [fixed] Description. (#16766).
  • Formatting: after updating, please run scripts/style.sh so the infra.check job passes. It needs clang-format 23 and swiftformat (see scripts/setup_check.sh). If you can't run it locally, the infra.check log lists the files that need formatting.

@paulb777 paulb777 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks. One note on reachability: with the shipping providers, both callbacks already arrive on the main queue. Auth delivers getToken on main, and App Check's callback runs on the Promises default queue, which is main. So this race can only happen if an app changes DispatchQueue.promises (FBLPromise.defaultDispatchQueue) or uses a custom interop provider. Could you mention that in the PR description?

The change itself is safe, and it finally puts the unused serialAuthArgsQueue to work.

Comment thread FirebaseStorage/Tests/Unit/StorageAuthorizerTests.swift Outdated
Comment thread FirebaseStorage/Sources/Internal/StorageTokenAuthorizer.swift
@dajiaohuang

Copy link
Copy Markdown
Contributor Author

Both semaphore waits now use two-second timeouts and XCTFail, while resumeBoth still releases both callback permits even after a timeout so the test cannot leave providers blocked indefinitely. Updated the PR description and Unreleased/#16766 changelog to state that concurrent callbacks require custom interop providers or a changed Promises default callback queue; shipping providers normally deliver on main.

Kept the existing serialAuthArgsQueue implementation, which you confirmed is safe, rather than switching to the optional notify-block alternative. Pinned SwiftFormat 0.55.5 lint and git diff --check pass. Native Apple XCTest is unrun locally and remains for CI.

@paulb777

paulb777 commented Oct 2, 2026

Copy link
Copy Markdown
Member

/gemini review

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

Copy link
Copy Markdown
Contributor

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 serializes Auth and App Check token header updates in StorageTokenAuthorizer using a serial queue to prevent concurrent mutation of requests, and adds corresponding unit tests. The review feedback recommends increasing the timeout values for semaphores and expectations in the new tests to 5 seconds to avoid potential flakiness on heavily loaded CI environments.

Comment thread FirebaseStorage/Tests/Unit/StorageAuthorizerTests.swift
Comment thread FirebaseStorage/Tests/Unit/StorageAuthorizerTests.swift
@paulb777 paulb777 added this to the 13.1.0 - M188 milestone Oct 2, 2026
@dajiaohuang

Copy link
Copy Markdown
Contributor Author

The revised bounded-wait regression now runs in the repository's actual Swift Package test target. At source 76fbd7f, StorageAuthorizerTests executed 17 tests with zero failures, including the parallel Auth/App Check header mutation regression: native XCTest results. The PR description retains the custom-provider/default-callback-queue reachability boundary.

This branch has not been deployed

No deployments
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.

5 participants