Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds support for deploying task queue triggers (onTaskDispatched) for Cloud Run functions, updating the fabricator and Run v2 service metadata serialization along with corresponding unit tests. The review feedback highlights two critical issues where an empty invoker array could be passed to run.setInvokerCreate or run.setInvokerUpdate, resulting in a FirebaseError crash. To resolve these, it is recommended to ensure the invoker array is non-empty before creation and to map a null invoker to ["private"] instead of [] during updates.
| } else if (backend.isTaskQueueTriggered(endpoint)) { | ||
| // Like HTTPS triggers, taskQueueTriggers have an invoker, but unlike HTTPS they don't default | ||
| // public. | ||
| const invoker = endpoint.taskQueueTrigger.invoker; | ||
| if (invoker && !invoker.includes("private")) { | ||
| await this.executor | ||
| .run(() => run.setInvokerCreate(endpoint.project, serviceName, invoker)) | ||
| .catch(rethrowAs(endpoint, "set invoker")); | ||
| } | ||
| } |
There was a problem hiding this comment.
In createRunFunction, if endpoint.taskQueueTrigger.invoker is an empty array ([]), invoker is truthy and !invoker.includes("private") is true, so it will call run.setInvokerCreate(..., []). However, run.setInvokerCreate (defined in src/gcp/run.ts) explicitly throws a FirebaseError if invoker.length === 0. To prevent this crash, we should also check invoker.length > 0 before calling run.setInvokerCreate.
| } else if (backend.isTaskQueueTriggered(endpoint)) { | |
| // Like HTTPS triggers, taskQueueTriggers have an invoker, but unlike HTTPS they don't default | |
| // public. | |
| const invoker = endpoint.taskQueueTrigger.invoker; | |
| if (invoker && !invoker.includes("private")) { | |
| await this.executor | |
| .run(() => run.setInvokerCreate(endpoint.project, serviceName, invoker)) | |
| .catch(rethrowAs(endpoint, "set invoker")); | |
| } | |
| } | |
| } else if (backend.isTaskQueueTriggered(endpoint)) { | |
| // Like HTTPS triggers, taskQueueTriggers have an invoker, but unlike HTTPS they don't default | |
| // public. | |
| const invoker = endpoint.taskQueueTrigger.invoker; | |
| if (invoker && invoker.length > 0 && !invoker.includes("private")) { | |
| await this.executor | |
| .run(() => run.setInvokerCreate(endpoint.project, serviceName, invoker)) | |
| .catch(rethrowAs(endpoint, "set invoker")); | |
| } | |
| } |
There was a problem hiding this comment.
Fixed in 2d0a65b: the create path now skips an empty invoker, with a test.
| } else if (backend.isTaskQueueTriggered(endpoint)) { | ||
| invoker = endpoint.taskQueueTrigger.invoker === null ? [] : endpoint.taskQueueTrigger.invoker; | ||
| } |
There was a problem hiding this comment.
In updateRunFunction, mapping endpoint.taskQueueTrigger.invoker === null to [] will cause run.setInvokerUpdate to be called with an empty array, which throws FirebaseError("Invoker cannot be an empty array"). In firebase-tools, the standard way to represent a private invoker is ["private"] (as seen in the tests for HTTPS triggers). Since the default for task queue triggers is private, null (which resets the invoker to default) should be mapped to ["private"] instead of []. Note: A similar issue exists in updateV2Function at line 903, which should also be updated to use ["private"] instead of [] to prevent the same crash.
| } else if (backend.isTaskQueueTriggered(endpoint)) { | |
| invoker = endpoint.taskQueueTrigger.invoker === null ? [] : endpoint.taskQueueTrigger.invoker; | |
| } | |
| } else if (backend.isTaskQueueTriggered(endpoint)) { | |
| invoker = endpoint.taskQueueTrigger.invoker === null ? ["private"] : endpoint.taskQueueTrigger.invoker; | |
| } |
There was a problem hiding this comment.
Fixed in 2d0a65b for Cloud Run: null now resets to ["private"] on update, with a test. The gcfv2 line (updateV2Function) predates this PR, so I left it out of scope here.
setTrigger and deleteTrigger threw for platform run, so an onTaskDispatched function on Cloud Run could not be deployed. - Create, update and disable the Cloud Tasks queue like for gcfv2. - Set the task queue invoker on Cloud Run create and update, with the same rules as gcfv2: no default, null on update means private. - Persist taskQueueTrigger in the firebase-functions-metadata annotation so the next deploy reads the service back as a task queue function instead of HTTPS.
run.setInvokerCreate and run.setInvokerUpdate throw on an empty array. Skip the create call for an empty invoker, and reset a null invoker to private on update.
a94fa33 to
2d0a65b
Compare
run.setInvokerCreate and run.setInvokerUpdate throw on an empty array. Skip the create call for an empty invoker, and reset a null invoker to private on update. Upstream: firebase#11558.
Description
Deploying an
onTaskDispatchedfunction on therunplatform (Cloud Run functions, e.g. Dart) fails withTask Queue triggers for Cloud Run functions are not supported yet.This PR adds task queue support for
run:setTriggeranddeleteTriggerupsert and disable the Cloud Tasks queue, as for gcfv2.createRunFunctionandupdateRunFunctionset the task queue invoker with the gcfv2 rules: no default,nullon update means private.serviceFromEndpointstorestaskQueueTriggerin thefirebase-functions-metadataannotation, andendpointFromServicereads it back. Without this, the next deploy reads the service as HTTPS and the planner refuses the change.It covers only task queues. #10838 covers task queues, schedules and blocking triggers together, but has been marked "do not merge" since July.
Scenarios Tested
run, invoker on create and update, private when there is no invoker, annotation round-trip.mocha 'src/deploy/**/*.spec.ts' 'src/gcp/**/*.spec.ts': 1775 passing.onTaskDispatchedfunction: create, unchanged re-deploy (an update, not an HTTPS→task queue change), OIDC dispatch from Cloud Tasks (204), retry after a 500, delete, then recreate.Sample Commands
firebase deploy --only functionsnow deploys task queue functions on Cloud Run.