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

Nextjs deployments are not turning off old cloud run revisions (for SSR)

Open ghost opened this issue 1 year ago • 7 comments

We use the nextjs framework integration for firebase. When we deploy our app, it creates a new cloud run revision for the SSR backend, but the old revision stays active. Rarely will the old one be 'deactivated'. Our snippet below gives the historical revisions for cloud run instances and you can see that one of them was deactivated successfully.

This matters because those old revisions are costing us a lot of money (which we recently discovered through billing and deleting many of the old revisions that were still active).

firebase-tools:12.7.0

[REQUIRED] Expected behavior

When we deploy a nextjs app, the old ssr cloud run revision should be deactivated when the new one is active.

[REQUIRED] Actual behavior

The old revisions are staying active.

image

ghost avatar Oct 31 '23 22:10 ghost

This issue does not seem to follow the issue template. Make sure you provide all the required information.

google-oss-bot avatar Oct 31 '23 22:10 google-oss-bot

For anyone experiencing similar issues, we are cleaning up our revisions with the following gcloud commands:

gcloud run revisions list --filter="status.conditions.type:Active AND metadata.creationTimestamp<'$(date --date=' 1 days ago' '+%Y%d%m')'" --format='value(metadata.name)' | xargs -r -L1 gcloud run revisions delete --quiet --region us-central1

Would be great to fix whatever is causing this issue with firebase deploy.

walter-cavinaw avatar Nov 02 '23 17:11 walter-cavinaw

Same here, thanks for the script!

MeTaNoV avatar Nov 08 '23 21:11 MeTaNoV

Are there any updates on this issue?

maksim-sidorenko avatar Dec 11 '23 13:12 maksim-sidorenko

Unfortunately this is WAI on the backend... minInstances will be respected in Cloud Functions gen2, so long as the revision is routable—this includes the tags made by the Firebase CLI so Hosting (SSG/CSR) and Functions (SSR) content can be deployed and rolled back atomically. In the next version of the CLI we will add guardrails to prevent minInstances from being configured alongside pinTags, #6684.

If you have any addition questions/concerns please reach out to Firebase support, sorry that we missed this in testing.

We'll add information on this to Web Frameworks' preview docs

jamesdaniels avatar Jan 18 '24 03:01 jamesdaniels

We use NextJs with Firebase Hosting with the web frameworks integration. Previously we where using both pinTags and minInstances at the same time since we required both functionalities, pinTags to do safe and quick rollbacks for the hosting (keeping in sync the Hosting and the "pinned" Cloud Function) , and minInstances to prevent a cold start when the hosting uses the Cloud Function to generate pages using Server Side Rendering. Specifically, the cold start doesn't happen with static pages, only when using SSR or pages with dynamic routes. I understand the dangers of having both features configured at once, is there any way that we can use both at the same time? Maybe adding a warning that needs to be accepted or something like that. Thanks!

erickborquez avatar Feb 01 '24 23:02 erickborquez

Just got burned by this. 3.4k USD later...

this one deletes everything except one with a given name (in my case the one serving traffic)

gcloud run revisions list --filter="-metadata.name:funcname-XXXXX-XXX" --format='value(metadata.name)' | xargs -r -L1 gcloud run revisions delete --quiet --region us-central1

CalebMacdonaldBlack avatar Feb 29 '24 01:02 CalebMacdonaldBlack