firebase / firebase-tools

The Firebase Command Line Tools
MIT License
3.97k stars 917 forks source link

Could not create or update Cloud Run service, Container Healthcheck failed #6465

Closed remie closed 8 months ago

remie commented 9 months ago

[REQUIRED] Environment info

firebase-tools: 12.6.2

Platform: CircleCI (cimg/node:16.18-browsers)

[REQUIRED] Test case

We use the following code to export the Cloud Tasks:

export const registerTaskHandlers = (container, options = {
    retryConfig: {
        maxAttempts: 3,
    },
    memory: '4GiB',
    timeoutSeconds: 1800
}) => {
    const appContainer = typeof container === 'function' ? container() : container;
    const taskHandlers = appContainer.isBound(TaskHandlers) ? appContainer.getAll(TaskHandlers) : [];
    taskHandlers.forEach(handler => {
        !isProduction() && logger.log(`[${handler.name}] Registering Task ${handler.name}`);
        module.exports[handler.name] = onTaskDispatched({ ...options, ...(handler.options || {}) }, ({ data }) => handler.process(data));
    });
};

The Cloud Task exports are picked up during yarn run firebase deploy -f --only functions in the CircleCI container:

i functions: updating Node.js 16 (2nd Gen) function VCSDeleteProjectConflictsTask(us-central1)... i functions: updating Node.js 16 (2nd Gen) function VCSDeleteProjectEntitiesTask(us-central1)... i functions: updating Node.js 16 (2nd Gen) function VCSDeleteScheduledJobTask(us-central1)... i functions: updating Node.js 16 (2nd Gen) function VCSLinkedProjectCreatedTask(us-central1)... i functions: updating Node.js 16 (2nd Gen) function VCSLinkedProjectDeletedTask(us-central1)... i functions: updating Node.js 16 (2nd Gen) function VCSLinkedProjectUpdatedTask(us-central1)... i functions: updating Node.js 16 (2nd Gen) function VCSPurgeConflictsTask(us-central1)... i functions: updating Node.js 16 (2nd Gen) function VCSPurgeOrphansTask(us-central1)... i functions: updating Node.js 16 (2nd Gen) function VCSPurgeTasksTask(us-central1)... i functions: updating Node.js 16 (2nd Gen) function VCSPurgeWebhooksTask(us-central1)... i functions: updating Node.js 16 (2nd Gen) function VCSSettingsUpdatedTask(us-central1)... i functions: updating Node.js 16 (2nd Gen) function VCSStateVerificationTask(us-central1)... i functions: updating Node.js 16 (2nd Gen) function VCSSynchroniseTask(us-central1)...

[REQUIRED] Steps to reproduce

N/A

[REQUIRED] Expected behavior

I would expect Firebase to register the Cloud Task and take care of all the plumbing in order to make onTaskDispatch work.

[REQUIRED] Actual behavior

The firebase deploy fails with the following error:

Could not create or update Cloud Run service [NAME], Container Healthcheck failed. Revision '[REVISION]' is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable. Logs for this revision might contain more information.

I am more than happy to provide actual GCP project information and log files privately if necessary.

remie commented 8 months ago

Ok, after some digging around I've discovered that the issue was actually related to some 1st gen code still being executed, which caused the 2nd gen deployment to fail. After migrating the v1 code to v2, the deployment succeeded.

Unfortunately, the deployment message was unclear. Perhaps this issue can be adjusted to provide better logging of failed deployment because the health check failure itself was not the real problem, it was the consequence of a deployment failure.

taeold commented 8 months ago

@remie Thanks for following up and lettings us know about the issue.

To make sure I understand the issue - the healthcheck failure was real, and it was because code related to 1st Gen function was failing for 2nd Gen?

What message was actually helpful in debugging your issue? I would love to find a way to expose them in the cli if possible.

google-oss-bot commented 8 months ago

Hey @remie. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 8 months ago

Since there haven't been any recent updates here, I am going to close this issue.

@remie if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

mudigone commented 4 months ago

Hey any update? I am facing this issue. I have a repo that uses alot of v1 cfs but have started to move the newer ones to v2, it has been working so far not sure what went wrong with this one.

mudigone commented 4 months ago

okay so I did something and it just worked fine, so I changed the structure of how my cloud functions were and introduced a new structure and in my index js I was importing index js of another root folder which exported all the cfs in the above folder. So one of the exports had a wrong case letter to the connected file and due to which gcp couldn't find the root target and I was getting the error, fixing that worked for me.

cyberpwnn commented 1 month ago

This is now happening for me all of the sudden.

waqadArshad commented 1 week ago

@taeold

Same here. adding a new 2nd Gen onSchedule function while all others are v1 functions, causes:

Could not create or update Cloud Run service sendschedulednotifications, Container Healthcheck failed. Revision 'sendschedulednotifications-00001-gem' is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable. Logs for this revision might contain more information.
nickjuntilla commented 6 days ago

I've spent 24 hours on this and still can't find the answer. We're being forced to upgrade to Gen 2 in september and i can't even deploy a test Gen 2 without failure. Even the most basic example of printing out the date from the docs doesn't work. It's always the same message.

"Could not create or update Cloud Run service test, Container Healthcheck failed. Revision 'test-00001-dah' is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable. Logs for this revision might contain more information."

Although it mentions a port I don't think it has anything to do with a port. Even responding to a simple http request fails. Even this fails: exports.date = onRequest((req, res) => { const date = new Date(); console.log(date) });

Also the log it refers to just repeats that message again.

HosokawaHazuki commented 5 days ago

おかしな場所でnpm installを行っていることが原因かもしれません。 npm installによって作成されたnode_modulesフォルダをすべて削除し、再度npm install→deployを行うとうまくいきました。

nickjuntilla commented 4 days ago

I found the answer to this for me in case anyone has the same issue. If you have Gen 1 and Gen 2 functions in the same file and you have a functions.config() ANYWHERE in your project your gen2 functions will not work. Unfortunately the error for this is that obscure port error and "unknown trigger" message. The fix is to convert your entire project to parameterized configuration: https://firebase.google.com/docs/functions/config-env?gen=2nd#params

Again even if you don't use functions.config() in your gen 2 functions, they will kill your deployment. Firebase makes it seem like you can mix and match gen1 and gen2, BUT YOU CANNOT. There might be a way if you use the new code division features, but with a regular project you cannot do it. Unfortunately this is not documented.

AndyKgotatso commented 1 day ago

I had to make this change