gotenberg: Cloud Run: 502 error

I’m experiencing an issue when running Gotenberg (8-cloudrun) on Google Cloud Run behind Cloudflare. Intermittently, I receive a 502: create request context: get multipart form: client disconnected when making POST requests to /forms/pdfengines/merge and /forms/chromium/convert/html.

This started happening around January 13th. Retrying the call multiple time can resolve the issue, but the root cause is unclear.

The command I’m using to run Gotenberg:

gotenberg --chromium-auto-start --chromium-disable-web-security --api-timeout=120s  --pdfengines-engines=qpdf,pdftk

Environment details:

  • Platform: Google Cloud Run
  • Proxy: Cloudflare

It seems like the issue could be related to timeout or protocol mismatches between Cloudflare, Cloud Run, and Gotenberg. Any guidance or suggestions on how to resolve this would be appreciated!

I try different versions of gotenberg.

If you have any insights into why these issues are occurring that might help me solve them.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 2
  • Comments: 20

Most upvoted comments

According to these docs it is not advised - even prohibited - to use such connection headers when using HTTP/2.

Hi, some update on this error,

I solve it by adding the following code to my axios request

import http from 'http';

const httpAgent = new http.Agent({ keepAlive: true})

const response = await axios.post(`${process.env.PDF_CONVERTER_URL}/forms/chromium/convert/html`, form, {
    httpAgent,
    responseType: 'stream',
},);

Adding HTTPAgent and keepAlive: true solve my issue.

I hope this can help someone else who is facing similar issues.

@stijntratsaertit yes, HTTP/2 definitely causes the error for me: {“retryCount”:1,“errorStatus”:502,“errorMessage”:“Request failed with status code 502”}

I have the same problem, except I don’t use CloudFlare. It also started recently.

I just enabled debug logging. Info logs only reported 200 on the Gotenberg side and 502 on the Cloud Run side.

I will try disabling HTTP/2 and report back. If that’s indeed the problem, I wonder if the recent Cloud Run v2 migration is related.

Disabling HTTP/2 solved it for me mostly, also disabled NGINX in proxy redirect and changed the startup probe with delay (all together works for me):

Image

Not sure if helpful but I am using https://github.com/starwalkn/gotenberg-go-client to connect to gotenberg. The command of how I deployed it:

gcloud run deploy gotenberg-prod
          --image=gotenberg/gotenberg:8.15.3-cloudrun
          --region=europe-west3
          --no-allow-unauthenticated
          --args=gotenberg
          --args="--api-port-from-env=PORT"
          --args="--api-timeout=300s"
          --args="--webhook-disable=true"
          --args="--chromium-restart-after=50"
          --memory=4Gi

--no-allow-unauthenticated is just for authentication, does not make a different of how stable it is.

So far the instance is running without any kind of connection issues.

The URL I am using to connect to the instance is the .run.app domain.