firebase-functions icon indicating copy to clipboard operation
firebase-functions copied to clipboard

onTaskDispatched with retry option is not working in firebase-functions v6

Open daniseijo opened this issue 1 year ago • 2 comments

Related issues

https://github.com/firebase/firebase-functions/issues/1618 - Tried the solution proposed there but it did nothing

[REQUIRED] Version info

node:

v20.12.2

firebase-functions:

6.0.1

firebase-tools:

13.20.2

firebase-admin:

12.6.0

[REQUIRED] Test case

I am following this example from the docs to create a cloud task. The only thing I am changing in my project is adding an option to avoid retries. If I add this in firebase-functions v6, and launch the emulator or try to deploy, it breaks.

[REQUIRED] Steps to reproduce

  • Create a new project from scratch with firebase init. In my case, I added typescript but I think it is irrelevant.
  • Update firebase-functions in the package.json to v6.0.1
  • Add a new onTaskDispatched function to the index.ts file and add the retry option:
import { onTaskDispatched } from 'firebase-functions/v2/tasks';

export const cloudTaskTest = onTaskDispatched({ retry: false }, (task) => {
  logger.info('Task dispatched', { task });
  return Promise.resolve();
});
  • Run npm run serve or npm run deploy either way an error will show:
⬢  functions: Failed to load function definition from source: FirebaseError: Failed to parse build specification

[REQUIRED] Expected behavior

The expected behavior should be for the emulator to create the queue. This behavior is achieved in version 5.1.0 for example:

✔  tasks: Created queue with key: queue:sample-project-us-central1-cloudTaskTest
✔  functions[us-central1-cloudTaskTest]: http function initialized (http://127.0.0.1:5001/sample-project/us-central1/cloudTaskTest).

[REQUIRED] Actual behavior

From version 6.0.1, the emulator returns the error copied above:

⬢  functions: Failed to load function definition from source: FirebaseError: Failed to parse build specification

And if I try to deploy it returns:

Error: Failed to parse build specification:
- FirebaseError Unexpected key 'endpoints[cloudTaskTest].taskQueueTrigger.retry'. You may need to install a newer version of the Firebase CLI.

Were you able to successfully deploy your functions?

No, I was not able. The error message was:

Error: Failed to parse build specification:
- FirebaseError Unexpected key 'endpoints[cloudTaskTest].taskQueueTrigger.retry'. You may need to install a newer version of the Firebase CLI.

daniseijo avatar Oct 02 '24 23:10 daniseijo

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

google-oss-bot avatar Oct 02 '24 23:10 google-oss-bot

I'm having this issue too. My firebase-tools version: 13.22.1

minhdanh avatar Oct 20 '24 02:10 minhdanh

Me too! Firebase tools version 13.28.0

I guess doing retry: false is the same as doing retryConfig: { maxAttempts: 1 }, no? That works fine for me.

guillermodlpa avatar Dec 07 '24 13:12 guillermodlpa

Hi, thanks for providing all the info. I will raise this with the team.

cabljac avatar Dec 17 '24 14:12 cabljac

Hi @cabljac, Is there any news about this issue? We want to update our project to v6 but are currently blocked because of this.

daniseijo avatar Jan 15 '25 16:01 daniseijo

By the looks of the API specification code, the retry option isn't supported for tasks. Has this worked previously in the past?

CorieW avatar Feb 24 '25 14:02 CorieW

We are using it for some cloud tasks in v5.0.1 together with the retryConfig object, and it is still in the types for v6.

daniseijo avatar Feb 24 '25 14:02 daniseijo

Thanks for the quick reply!

Do you know what firebase-tools version was used when deploying the cloud tasks in v5.0.1?

CorieW avatar Feb 24 '25 14:02 CorieW

We are using the latest version: v13.31.2

daniseijo avatar Feb 24 '25 16:02 daniseijo

Okay, yeah it does work in v5.0.1 up until (and before) v5.1.1, due to this change.

I logged the parameters that are sent to firebase-tools, and retry isn't included in v5.0.1, but is in v5.1.1 (and v6).

v5.1.1 (and v6):

{
  "platform": "gcfv2",
  "availableMemoryMb": null,
  "timeoutSeconds": null,
  "minInstances": null,
  "maxInstances": null,
  "ingressSettings": null,
  "concurrency": null,
  "serviceAccountEmail": null,
  "vpc": null,
  "labels": {},
  "taskQueueTrigger": {
    "retryConfig": {
      "maxAttempts": 1,
      "maxDoublings": null,
      "maxBackoffSeconds": null,
      "maxRetrySeconds": null,
      "minBackoffSeconds": null
    },
    "rateLimits": {
      "maxConcurrentDispatches": null,
      "maxDispatchesPerSecond": null
    },
    "retry": false
  },
  "entryPoint": "cloudTaskTest"
}

firebase-tools throws an error here, as the API specification doesn't allow the retry option with tasks.

v5.0.1 (and before):

{
  "platform": "gcfv2",
  "availableMemoryMb": null,
  "timeoutSeconds": null,
  "minInstances": null,
  "maxInstances": null,
  "ingressSettings": null,
  "concurrency": null,
  "serviceAccountEmail": null,
  "vpc": null,
  "labels": {},
  "taskQueueTrigger": {
    "retryConfig": {
      "maxAttempts": 1,
      "maxDoublings": null,
      "maxBackoffSeconds": null,
      "maxRetrySeconds": null,
      "minBackoffSeconds": null
    },
    "rateLimits": {
      "maxConcurrentDispatches": null,
      "maxDispatchesPerSecond": null
    }
  },
  "entryPoint": "cloudTaskTest"
}

firebase-tools does not throw an error here, because no retry option is passed.

It could be that retry has no function. Are you able to verify whether the retry option on your current v5.0.1 function does anything? It seems to me that retry=false could probably be replicated with retryConfig: { maxAttempts: 1 }.

CorieW avatar Feb 25 '25 09:02 CorieW