Skip to content

Can not hook into SIGTERM handling in Cloud Run #704

@iq-dot

Description

@iq-dot

Hi everyone,

I am using functions framework to deploy a docker container to Cloud Run, everything is fine but when it is scaling down Cloud Run will send a SIGTERM which by default has no handling and can look like an error:

DEFAULT 2025-09-25T17:44:55.248566Z npm error path /app/functions
DEFAULT 2025-09-25T17:44:55.248635Z npm error command failed
DEFAULT 2025-09-25T17:44:55.248739Z npm error signal SIGTERM
DEFAULT 2025-09-25T17:44:55.248795Z npm error command sh -c functions-framework --source=dist/index.js --target=$FUNCTION_TARGET --signature-type=$FUNCTION_SIGNATURE_TYPE
DEFAULT 2025-09-25T17:44:55.251374Z npm notice

I had hoped to hook into the SIGTERM in my index.js as follows:

// handle sigterm and sigint

process.on("SIGTERM", () => {
	console.info("SIGTERM received - shutting down");
	process.exit(0);
});

However this never executes and it seems like functions-framework is handling this.

I start the app in my dockerfile like so:

CMD ["npm", "run", "start"]

Is there anything I can do to have a more graceful shutdown that I can handle in my code?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions