Repository navigation
fix(functions): retry on HTTP 400 service account propagation errors during function creation - #11047
Conversation
|
Warning Gemini encountered an error creating the review. You can try again by commenting |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the deployment process to prevent deadlocks and stale source tokens during Cloud Functions deployment retries by introducing a withToken wrapper in SourceTokenScraper that automatically aborts on failure. Additionally, it updates the deployment executor to retry Cloud Functions creation on HTTP 400 errors caused by service account propagation delays, specifically targeting dynamically provisioned service accounts. The reviewer suggested adding a defensive guard in isServiceAccount404 to prevent potential runtime TypeError exceptions when the error object is null or undefined.
| export const isServiceAccount404: RetryPredicate = (err: any): boolean => { | ||
| if (parseErrorCode(err) !== 404) { | ||
| const code = parseErrorCode(err); |
There was a problem hiding this comment.
To prevent potential runtime TypeError exceptions when err is null or undefined, we should add a defensive guard at the beginning of isServiceAccount404 before calling parseErrorCode(err).
| export const isServiceAccount404: RetryPredicate = (err: any): boolean => { | |
| if (parseErrorCode(err) !== 404) { | |
| const code = parseErrorCode(err); | |
| export const isServiceAccount404: RetryPredicate = (err: any): boolean => { | |
| if (!err) { | |
| return false; | |
| } | |
| const code = parseErrorCode(err); |
There was a problem hiding this comment.
This is pre-existing problem to my change and its' also true of all the error handling classes in this file. It's good feedback, but we should instead do a separate PR that cleans this up overall and likely moves a bunch of this into error.ts as it's pretty generic. So unless someone really pushes the issue I won't do anything here.
In practice, having run 70+ deployments to test this code and flakiness removal, in practice it's always been fine and I don't think a null/undefined/non-object value is every being passed in.
bb09ce9 to
a50cc3b
Compare
shettyvarun268
left a comment
There was a problem hiding this comment.
LGTM with some minor non-blocking comments
…during function creation ### Description When deploying Cloud Functions with declarative security, the CLI provisions a dedicated managed service account (`firebase-fn-[0-9]+@<project>.iam.gserviceaccount.com`). While the service account is created and granted roles prior to function deployment, IAM propagation is eventually consistent across Google Cloud backend services. When creating event-triggered Cloud Functions (such as Eventarc triggers), downstream validation can fail if the newly provisioned service account has not yet replicated to the trigger service. Because the trigger validator treats an unpropagated service account as an invalid request parameter rather than a missing URL resource, the API returns HTTP 400 (INVALID_ARGUMENT: "The request was invalid: invalid service account ... provided") rather than HTTP 404 (NOT_FOUND). Previously, `executor.isServiceAccount404` only recognized HTTP 404 errors, causing function creation to fail immediately on HTTP 400 without retrying. This change updates `isServiceAccount404` in `src/deploy/functions/release/executor.ts` to retry HTTP 400 errors caused by service account propagation delays. To prevent false positives and avoid retrying when a developer has made a typo in a custom service account configuration, HTTP 400 retries are specifically restricted to dynamically provisioned declarative security service accounts matching `firebase-fn-[0-9]+@`. ### Scenarios Tested - Unit tests in `src/deploy/functions/release/executor.spec.ts` verifying: - Retry on HTTP 404 and HTTP 400 service account propagation errors for `firebase-fn-[0-9]+@` accounts - Immediate failure on HTTP 400 for user-configured custom service accounts without retrying - Unit tests in `src/deploy/functions/release/fabricator.spec.ts` verifying: - QueueExecutor retries `createV2Function` and succeeds when encountering HTTP 400 service account propagation errors - npm run test - Manual testing deploying and deleting functions with kits. ### Sample Commands firebase deploy --only functions:storage-resize-images
a50cc3b to
a6565f6
Compare
Description
When deploying Cloud Functions with declarative security, the CLI provisions a dedicated managed service account (
firebase-fn-[0-9]+@<project>.iam.gserviceaccount.com). While the service account is created and granted roles prior to function deployment, IAM propagation is eventually consistent across Google Cloud backend services.When creating event-triggered Cloud Functions (such as Eventarc triggers), downstream validation can fail if the newly provisioned service account has not yet replicated to the trigger service. Because the trigger validator treats an unpropagated service account as an invalid request parameter rather than a missing URL resource, the API returns HTTP 400 (INVALID_ARGUMENT: "The request was invalid: invalid service account ... provided") rather than HTTP 404 (NOT_FOUND).
Previously,
executor.isServiceAccount404only recognized HTTP 404 errors, causing function creation to fail immediately on HTTP 400 without retrying.This change updates
isServiceAccount404insrc/deploy/functions/release/executor.tsto retry HTTP 400 errors caused by service account propagation delays. To prevent false positives and avoid retrying when a developer has made a typo in a custom service account configuration, HTTP 400 retries are specifically restricted to dynamically provisioned declarative security service accounts matchingfirebase-fn-[0-9]+@.Scenarios Tested
src/deploy/functions/release/executor.spec.tsverifying:firebase-fn-[0-9]+@accountssrc/deploy/functions/release/fabricator.spec.tsverifying:createV2Functionand succeeds when encountering HTTP 400 service account propagation errorsSample Commands
firebase deploy --only functions:storage-resize-images