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.