How Cloud Run's request timeout works, from the 300-second default to the 60-minute maximum, why requests end in HTTP 504, and when to move long work off the request path.

A Cloud Run service has 300 seconds to answer each request by default, and anything slower gets an HTTP 504 with "The request has been terminated because it has reached the maximum request timeout." The limit can go up to 3,600 seconds per service.
Raising it is a one-line fix, and it is often the wrong one when the work belongs outside the request.
The request timeout docs set the default at 5 minutes and the maximum at 60 minutes for services. For anything above 15 minutes, Google recommends retries and handlers that tolerate the client reconnecting.
The job and shutdown values are from the Cloud Run jobs docs and the container runtime contract, checked on November 20, 2026.
# On deploy
gcloud run deploy reports --image=europe-west1-docker.pkg.dev/my-project/apps/reports:v42 \
--region=europe-west1 --timeout=900
# On an existing service
gcloud run services update reports --region=europe-west1 --timeout=15m
In a service YAML it is spec.template.spec.timeoutSeconds, and in Terraform the timeout field on the template of google_cloud_run_v2_service. The change creates a new revision.
It tells you the response never finished, and the troubleshooting guide suggests tracing where the time went before raising anything. The usual causes are:
attemptDeadline, so a 10-minute service timeout does not help a scheduled call.Cloud Run does not stop your code when it sends the 504. The handler keeps running, and the client, seeing a failure, often retries and starts the same work twice.
When it takes longer than a person or caller should wait, which is usually a few seconds. The request should record the job, publish a message and return an ID, and the client polls or gets notified when it is done. Pub/Sub push to Cloud Run allows acknowledgement deadlines up to 600 seconds per message, per the Pub/Sub subscription properties, and for work beyond that, a Cloud Run job runs batches of tasks for up to 168 hours each.
Splitting the work helps more than any timeout: an export for 40 accounts published as 40 messages gets 40 short handlers that retry independently, instead of one 25-minute request that fails at minute 24.
Encore is a backend framework with built-in infrastructure, so the topic, subscription, bucket and database for this pattern are declared in application code, and deploying to GCP provisions Pub/Sub, Cloud Storage and Cloud SQL in your own project with services on Cloud Run, per the GCP infrastructure docs. The request returns in milliseconds, and the work runs in Pub/Sub handlers with their own retries.

Run in your terminal to get started locally.
An export that used to run inside one request, split into one message per account:
// exports/exports.ts
import { api, APIError } from "encore.dev/api";
import { SQLDatabase } from "encore.dev/storage/sqldb";
import { Bucket } from "encore.dev/storage/objects";
import { Topic, Subscription } from "encore.dev/pubsub";
const db = new SQLDatabase("exports", { migrations: "./migrations" });
const files = new Bucket("export-files");
interface AccountExport {
exportId: string;
accountId: string;
}
const accountExports = new Topic<AccountExport>("account-exports", {
deliveryGuarantee: "at-least-once",
});
// Returns an ID right away; the work happens in the subscription.
export const start = api(
{ expose: true, method: "POST", path: "/exports" },
async ({ accountIds }: { accountIds: string[] }): Promise<{ exportId: string }> => {
if (accountIds.length === 0) throw APIError.invalidArgument("no accounts");
const exportId = crypto.randomUUID();
await db.exec`
INSERT INTO exports (id, total) VALUES (${exportId}, ${accountIds.length})`;
for (const accountId of accountIds) {
await accountExports.publish({ exportId, accountId });
}
return { exportId };
},
);
// One short handler per account, retried on its own if it fails.
new Subscription(accountExports, "write-account-file", {
ackDeadline: "120s",
handler: async ({ exportId, accountId }) => {
const rows = await db.queryAll<{ id: string; total_cents: number }>`
SELECT id, total_cents FROM invoices WHERE account_id = ${accountId}`;
const csv = ["id,total_cents", ...rows.map((r) => `${r.id},${r.total_cents}`)].join("\n");
// Same key on redelivery, so a retry overwrites instead of duplicating.
await files.upload(`${exportId}/${accountId}.csv`, Buffer.from(csv), {
contentType: "text/csv",
});
await db.exec`
INSERT INTO export_parts (export_id, account_id) VALUES (${exportId}, ${accountId})
ON CONFLICT DO NOTHING`;
},
});
export const status = api(
{ expose: true, method: "GET", path: "/exports/:id" },
async ({ id }: { id: string }): Promise<{ done: number; total: number }> => {
const row = await db.queryRow<{ done: number; total: number }>`
SELECT (SELECT count(*)::int FROM export_parts WHERE export_id = e.id) AS done, e.total
FROM exports e WHERE e.id = ${id}`;
if (!row) throw APIError.notFound("export not found");
return row;
},
);
-- exports/migrations/1_init.up.sql
CREATE TABLE exports (
id UUID PRIMARY KEY,
total INTEGER NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE TABLE export_parts (
export_id UUID NOT NULL REFERENCES exports (id),
account_id TEXT NOT NULL,
PRIMARY KEY (export_id, account_id)
);
CREATE TABLE invoices (
id TEXT PRIMARY KEY,
account_id TEXT NOT NULL,
total_cents INTEGER NOT NULL
);
On GCP, the subscription gets a dead-letter topic, so a message that keeps failing stops retrying instead of looping. The object storage docs cover signed download URLs for handing the finished files to the client. Locally, encore run starts the database, topic and bucket for the same code, so the whole flow can be tested before a deploy.
A coding agent asked to fix a 504 can make this change in one pull request, adding the topic and subscription next to the endpoint and running the export locally, with no Pub/Sub or IAM setup in the GCP console.
Best fit: Teams on Cloud Run with exports, imports or reports that outgrow a request and want the queue, storage and retries in the service code.
Raise --timeout when a request needs a few more minutes and the caller will wait. Otherwise, give queries and outbound calls their own deadlines, return an ID from the request, and move the work to Pub/Sub messages or a Cloud Run job.
The default is 5 minutes (300 seconds), and you can raise it to a maximum of 60 minutes (3,600 seconds) per service with gcloud run deploy --timeout or gcloud run services update --timeout.
The service did not return a response before the request timeout, and Cloud Run ended the request with HTTP 504 'The request has been terminated because it has reached the maximum request timeout.' The container may keep running the handler after the client gets the 504.
No. 3,600 seconds is the limit for services. Work that takes longer belongs in a Cloud Run job, whose tasks default to a 10-minute timeout and can be configured up to 168 hours.
No. It only helps when the work needs the time, since a request that waits on a slow database query or an outbound call without a timeout will still be slow, and Google recommends retries and idempotent handlers for anything over 15 minutes.
Deploy to your cloud on AWS and Google Cloud
without managing infrastructure
Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.