invoiceninja / dockerfiles

Docker files for Invoice Ninja
https://hub.docker.com/r/invoiceninja/invoiceninja
GNU General Public License v2.0
412 stars 267 forks source link

504 Gateway Timeout, SnapPDF timeout, Chromium-browser errors #493

Open rombie18 opened 1 year ago

rombie18 commented 1 year ago

Setup information Running Invoice Ninja using docker-compose on a Raspberry Pi 3B+, arm64 v8.

Describe the bug The SnapPDF previews are not working and are timing out with error 504 Gateway Timeout.

To reproduce Steps to reproduce the behavior:

  1. Go to 'Edit invoice design'
  2. PDF preview does not generate and times out

Expected behavior A pdf preview or invoice should be generated.

Logs/Stacktrace When tying to manually save a website as pdf inside the dockerfiles-app container, the following error is generated. This explains the 504 Gateway Timeout. It seems that the chromium-browser process is causing the timeout.

~ $ ~/vendor/bin/snappdf convert --url https://github.com save.pdf -vvv
Downloading https://github.com and saving it to save.pdf

In Process.php line 1152:

  [Symfony\Component\Process\Exception\ProcessTimedOutException]
  The process "'/usr/bin/chromium-browser' '--headless' '--disable-gpu' '--disable-translate' '--disable-extensions' '--disable-sync' '--disable-backgrou
  nd-networking' '--disable-software-rasterizer' '--disable-default-apps' '--disable-dev-shm-usage' '--safebrowsing-disable-auto-update' '--run-all-compo
  sitor-stages-before-draw' '--no-first-run' '--no-margins' '--no-sandbox' '--print-to-pdf-no-header' '--hide-scrollbars' '--ignore-certificate-errors' '
  --print-to-pdf=/tmp/pdf_AmECpk.pdf' 'https://github.com'" exceeded the timeout of 60 seconds.

Exception trace:
  at /var/www/app/vendor/symfony/process/Process.php:1152
 Symfony\Component\Process\Process->checkTimeout() at /var/www/app/vendor/symfony/process/Process.php:423
 Symfony\Component\Process\Process->wait() at /var/www/app/vendor/symfony/process/Process.php:249
 Symfony\Component\Process\Process->run() at /var/www/app/vendor/beganovich/snappdf/src/Snappdf.php:257
 Beganovich\Snappdf\Snappdf->generate() at /var/www/app/vendor/beganovich/snappdf/src/Snappdf.php:272
 Beganovich\Snappdf\Snappdf->save() at /var/www/app/vendor/beganovich/snappdf/src/Command/ConvertHtmlToPdfCommand.php:76
 Beganovich\Snappdf\Command\ConvertHtmlToPdfCommand->execute() at /var/www/app/vendor/symfony/console/Command/Command.php:312
 Symfony\Component\Console\Command\Command->run() at /var/www/app/vendor/symfony/console/Application.php:1022
 Symfony\Component\Console\Application->doRunCommand() at /var/www/app/vendor/symfony/console/Application.php:314
 Symfony\Component\Console\Application->doRun() at /var/www/app/vendor/symfony/console/Application.php:168
 Symfony\Component\Console\Application->run() at /var/www/app/vendor/beganovich/snappdf/snappdf:28
 include() at /var/www/app/vendor/bin/snappdf:120

convert [--url URL] [--html HTML] [--binary BINARY] [--] <path>

I was able to further narrow down the issue to be a timout of the Chromium browser used by the SnapPDF executable. When using the chromium-browser to try to print a pdf the following error is generated:

Heads up! Careful with the /usr/bin/chromium-browser --headless --disa.... command, this may freeze your system!

~ $ /usr/bin/chromium-browser --headless --disable-gpu --disable-translate --disable-extensions --disable-sync --disable-background-networking --disable-sof
tware-rasterizer --disable-default-apps --disable-dev-shm-usage --safebrowsing-disable-auto-update --run-all-compositor-stages-before-draw --no-first-run --
no-margins --no-sandbox --print-to-pdf-no-header --hide-scrollbars --ignore-certificate-errors --print-to-pdf=/tmp/pdf_GMppJK.pdf https://github.com
[0207/201126.570219:WARNING:dns_config_service_linux.cc(427)] Failed to read DnsConfig.
[0207/201126.666059:ERROR:bus.cc(397)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
[0207/201126.666646:ERROR:bus.cc(397)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
[0207/201126.792539:ERROR:gpu_init.cc(440)] Passthrough is not supported, GL is disabled, ANGLE is
[0207/201126.866444:WARNING:bluez_dbus_manager.cc(248)] Floss manager not present, cannot set Floss enable/disable.
[0207/201127.190327:WARNING:dns_config_service_linux.cc(427)] Failed to read DnsConfig.

This log made me suspect there was a problem with dns resolution but when manually trying a nslookup and ping inside the container to github.com, this did resolve to an ip adress. At this point I am a bit stuck and I can't seem to find a reason why the chromium process causes these errors.

Docker/Kubernetes/Helm:

Server: Docker Engine - Community Engine: Version: 23.0.0 API version: 1.42 (minimum version 1.12) Go version: go1.19.5 Git commit: d7573ab Built: Wed Feb 1 17:44:38 2023 OS/Arch: linux/arm64 Experimental: false containerd: Version: 1.6.16 GitCommit: 31aa4358a36870b21a992d3ad2bef29e1d693bec runc: Version: 1.1.4 GitCommit: v1.1.4-0-g5fd4c4d docker-init: Version: 0.19.0 GitCommit: de40ad0



**Additional context**
My Raspberry Pi does sometimes have a substantial load on it which also could cause a timeout, however I don't think this is the problem here since the chromium-browser process generates errors.
turbo124 commented 1 year ago

@rombie18

I think you are on the right track, I believe this issue is a DNS resolution issue from within the container itself.

rombie18 commented 1 year ago

I did suspect this as well but when I do a ping or nslookup inside the container this does resolve to an ip address.