Skip to content

Raising memory on an existing 2nd gen function keeps the old CPU, so deploys above 4GiB fail #11492

Open

Description

@CorieW

[REQUIRED] Environment info

firebase-tools: 15.34.0

Platform: Linux

[REQUIRED] Test case

const { onRequest } = require("firebase-functions/v2/https");

exports.cpubugtest = onRequest(
  { region: "us-central1", memory: "512MiB" }, // no cpu set
  (req, res) => res.send("ok"),
);

[REQUIRED] Steps to reproduce

  1. Deploy the function above with memory: "512MiB". It gets 1 CPU.
  2. Change memory to "4GiB" and deploy again.
  3. Change memory to "8GiB" and deploy again.

[REQUIRED] Expected behavior

When cpu isn't set, the CLI picks the CPU based on memory, the same as it does for a new function:

Memory Existing function New function
4GiB 2 CPU 2 CPU
8GiB 2 CPU, deploy works 2 CPU

[REQUIRED] Actual behavior

The function keeps its old CPU (1):

  • At 4GiB, the deploy works, but the function has 1 CPU instead of 2.
  • At 8GiB, the deploy fails:
HTTP Error: 400, Could not update Cloud Run service projects/<project>/locations/us-central1/services/cpubugtest. spec.template.spec.containers[0].resources.limits.memory: Invalid value specified for container memory. For 1.0 CPU, memory must be between 128Mi and 4Gi inclusive.

Cause: In src/deploy/functions/prepare.ts, if cpu isn't set, the CLI copies the CPU from the function that's already deployed:

if (typeof wantE.cpu === "undefined" && haveE.cpu) {
  wantE.cpu = haveE.cpu;
}

Because cpu now has a value, resolveCpuAndConcurrency doesn't pick a CPU based on memory, and the old CPU is sent in the update.

Workaround: Set cpu yourself (for example cpu: 2).

Activity

  1. aalej commented on Nov 16, 2026

    @aalej
    Contributor

    Thanks for opening this report and for providing a clear repro along with your findings, @CorieW! I was able to reproduce the issue, and I think your observations are correct. Since the CLI copies the functions previously set cpu when it isn't explicitly provided, it will skip memoryToGen2Cpu in resolveCpuAndConcurrency which could lead to an invalid cpu value.

    It looks like there is an open PR #11526, which is currently being reviewed, that addresses this behavior. While waiting for the fix to get merged, for anyone also encountering this issue, the workaround specified in the report should get you unblocked.

    const { onRequest } = require("firebase-functions/v2/https");
    
    exports.cpubugtest = onRequest(
      {
        region: "us-central1",
        memory: "8GiB",
        cpu: 2 // expicitly set cpu
      },
      (req, res) => res.send("ok"),
    );

    Marking this as reproducible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions