rahul190201

rahul190201

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.

Marked As Solved

shamanime

shamanime

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)},

Also Liked

shamanime

shamanime

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?

rahul190201

rahul190201

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

Last Post!

rahul190201

rahul190201

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

Where Next?

Popular in Questions Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement