Chromic_pdf ChromicPDF.Connection.ConnectionLostError in production environment

After pushing some recent changes in my Phoenix application where I am using ChromicPDF to generate pdf files, I am getting the following error on my production server:

17:12:40.189 [error] GenServer #PID<0.2553.0> terminating
** (ChromicPDF.Connection.ConnectionLostError) Chrome has stopped or was terminated by an external program.

If this happened while you were printing a PDF, this may be a problem with Chrome itelf.
If this happens at startup and you are running inside a Docker container with a Linux-based
image, please see the "Chrome Sandbox in Docker containers" section of the documentation.

Either way, to see Chrome's error output, configure ChromicPDF with the option

    discard_stderr: false

    (chromic_pdf 1.17.0) lib/chromic_pdf/pdf/connection/local.ex:49: ChromicPDF.Connection.Local.handle_info/2
    (stdlib 3.15.2) gen_server.erl:695: :gen_server.try_dispatch/4
    (stdlib 3.15.2) gen_server.erl:771: :gen_server.handle_msg/6
    (stdlib 3.15.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: {:DOWN, #Reference<0.369492350.2377121803.250295>, :port, #Port<0.21>, :normal}

I am not getting this error on my local. I tried to follow the documentation in the section Chrome Sandbox in Docker containers, but couldn’t make the required changes successfully. I tried using ChatGPT for help with making changes in the dockerfile of the project and the ingress and deployment .yml files but it did not work.

I am passing the following to the chromic_pdf_opts in application.ex

session_pool: [timeout: 60_000, size: 10, checkout_timeout: 60_000]

I was trying a fix suggested by claude.ai, so I updated the config as follows in config.ex

# chromic_pdf config for all environments
config :chromic_pdf, :chrome_args, [
  "--no-sandbox",
  "--disable-setuid-sandbox",
  "--disable-gpu",
  "--disable-dev-shm-usage",
  "--remote-debugging-port=9222"
]

Even this did not solve the problem.

Please let me know if I should share any other details which could help better understand the problem. Any help or suggestions would be highly appreciated.

Add that to your options and inspect the new output when it errors.

  1. Are you able to print anything in prod? Is the error happening at startup or when you’re printing?

  2. How are you installing Chrome in your prod server?

1 Like

Hey @rahul190201

could it be that your changes included a Chrome update to v128+? Failed to print using chromium=128.0.6613.84-1~deb12u1 · Issue #326 · bitcrowd/chromic_pdf · GitHub

Here’s the code snippet from the dockerfile for Chrome installation

# Install Chrome
RUN apt-get update && \
    apt-get install -y wget gnupg && \
    wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
    echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list && \
    apt-get update && \
    apt-get install -y google-chrome-stable && \
    rm -rf /var/lib/apt/lists/*

[quote="shamanime, post:2, topic:66062"]
Add that to your options and inspect the new output when it errors.
[/quote]

I did but couldn't see a different output. This is the output that I am getting now:

08:43:04.082 [error] GenServer #PID<0.2553.0> terminating
** (ChromicPDF.Connection.ConnectionLostError) Chrome has stopped or was terminated by an external program.

If this happened while you were printing a PDF, this may be a problem with Chrome itelf.
If this happens at startup and you are running inside a Docker container with a Linux-based
image, please see the “Chrome Sandbox in Docker containers” section of the documentation.

Either way, to see Chrome’s error output, configure ChromicPDF with the option

discard_stderr: false

(chromic_pdf 1.17.0) lib/chromic_pdf/pdf/connection/local.ex:49: ChromicPDF.Connection.Local.handle_info/2
(stdlib 3.15.2) gen_server.erl:695: :gen_server.try_dispatch/4
(stdlib 3.15.2) gen_server.erl:771: :gen_server.handle_msg/6
(stdlib 3.15.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

[quote="shamanime, post:2, topic:66062"]
* Are you able to print anything in prod? Is the error happening at startup or when you’re printing?
[/quote]

The error is happening at startup and the docker container crashes.


I also deploy with Docker.
With the debian:bookworm-20240904-slim image, I only install chromium without adding any source.

My only prod config is:

config :myapp, ChromicPDF,
  no_sandbox: true

And then I start it on the application with:

{ChromicPDF, Application.get_env(:myapp, ChromicPDF)},
1 Like

Yes, we switched to Chromium and the problem is fixed.