Search code examples
javagoogle-cloud-platformquarkusgoogle-cloud-run

504 The request has been terminated because it has reached the maximum request timeout GCP


I have two Google Cloud Run services called 'A' that make client rest calls to another service 'B' to get information from a MongoDB database. The strange thing is that the request made https://A/revisions/463fc2ce-9140-47f7-8294-240a5640a49b/pages sometimes produces 504 errors with the message 'The request has been terminated because it has reached the maximum request timeout', however the same call but with a different revision id eg: https://A/revisions/543fc2ce-9140-47f7-8294-240a5640a49b/pages there is no problem, the first revision brings less information in the response than the second revision.

Looking at the logs of client 'B' I have been able to observe that it shows the message of type warning: Truncated response body. It usually implies that the request timed out or the application exited before the response was finished.

I have also been able to observe that there is no problem with CPU or memory and in both cases the CPU is always active.

This is the configuration that I have in the yaml in both services:

resource_requests:
cpu: 1
memory: 512
resource_limits:
cpu: 1
memory: 512
min_scale: 1
max_scale: 100
cloud_run_gen: gen2
ports:
name: http1
port: 8080
startup_cpu_boost: true
cpu_always_allocated: true

What could be happening?


Solution

  • If your service is processing long requests, you can increase the request timeout.

    The timeout is set by default to 5 minutes (300 seconds) and can be extended up to 60 minutes (3600 seconds).

    gcloud run services update [SERVICE] --timeout=[TIMEOUT]