westy92/html-pdf-chrome

Timeout problem w/ external chrome browser

leafarenuk opened this issue · 0 comments

Hi all,
I always run into this error when mutiple people call the pdf.toBuffer() function the same time / mutiple API calls are made synchronously to create a pdf..

Error: connect ETIMEDOUT 159.XX.XXX.XXX:9222
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1159:16)
    at TCPConnectWrap.callbackTrampoline (internal/async_hooks.js:130:17)

If have set the host in the options:

  host: "159.XX.XXX.XXX",
  port: "9222",

I use an external hosted Chrome in a docker container on a Hetzner server.
The docker-compose file looks like:

version: "2"
services:
  chrome:
    image: justinribeiro/chrome-headless:latest
    command: ["chromium-browser", "--headless", "--disable-gpu", "--no-sandbox", "--remote-debugging-address=0.0.0.0", "--remote-debugging-port=9222", "--disable-extensions", "--disable-dev-shm-usage", "--disable-features=dbus", "--disable-software-rasterizer"]
    restart: always
    ports:
      - "9222:9222"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://159.XX.XXX.XXX:9222"]
      interval: 10s
      timeout: 5s
      retries: 5
    logging:
      options:
        max-size: "10m"
        max-file: "3"
    mem_limit: 4g 
    cpus: 3.0 

The chrome instance looks like this.
CleanShot 2024-02-15 at 18 57 12@2x

@westy92 Is there anything I need to consider?