chrome headless crashes with Cannot allocate memory error

#1
Hello,

Trying to get chrome headless working here. But it keeps crashing.

We have a PHP application named snappdf which uses exec() function to lunch chrome headless to create PDF files. And it crashes when we open a script in a browser. The chrome returns exit code 133. If we do a strace of the process then we can see the following in /usr/local/lsws/logs/stderr.log:

Code:
getrandom("\x5d\x14\x34\xdc\xbc\xbc\x90\xe9", 8, 0) = 8
mmap(0x352400000000, 17179869184, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x352400000000
mmap(0xf6bfffff000, 17179873280, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory)
mmap(0xf6bfffff000, 17179873280, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory)
write(2, "../../base/allocator/partition_a"..., 91../../base/allocator/partition_allocator/partition_address_space.cc(76) Check failed: false) = 91
write(2, "\n", 1
)                       = 1
--- SIGTRAP {si_signo=SIGTRAP, si_code=SI_KERNEL} ---
+++ killed by SIGTRAP (core dumped) +++
Trace/breakpoint trap (core dumped)
The output of the mmap() system call shows a process of chrome attempts to reserve a virtual memory space of 16 gigabytes but it fails and returns an ENOMEM error code.

The same error happens if we don't use snappdf and try a raw exec() to call chrome headless. I already increased a limit on virtual RAM in LiteSpeed:

Code:
    <memSoftLimit>32G</memSoftLimit>
    <memHardLimit>32G</memHardLimit>
and exec("ulimit -a") gives the following output:

Code:
real-time non-blocking time  (microseconds, -R) unlimited
core file size              (blocks, -c) 0
data seg size               (kbytes, -d) unlimited
scheduling priority                 (-e) 0
file size                   (blocks, -f) unlimited
pending signals                     (-i) 63544
max locked memory           (kbytes, -l) unlimited
max memory size             (kbytes, -m) unlimited
open files                          (-n) 655350
pipe size                (512 bytes, -p) 8
POSIX message queues         (bytes, -q) 819200
real-time priority                  (-r) 0
stack size                  (kbytes, -s) 8192
cpu time                   (seconds, -t) unlimited
max user processes                  (-u) 1400
virtual memory              (kbytes, -v) 33554432
file locks                          (-x) unlimited
The script and chrome are working fine if use a CLI call from a SSH sessions, i.e. outside Litespeed:

Code:
$bin_file = '/opt/google/chrome/google-chrome';
#$bin_file = '/usr/local/sbin/chrome-devel-sandbox';
$cmd = 'export HOME=/home/admin; '. $bin_file .' --headless --disable-gpu --disable-translate --disable-extensions --disable-sync --disable-background-networking --disable-software-rasterizer --disable-default-apps --disable-dev-shm-usage --safebrowsing-disable-auto-update --run-all-compositor-stages-before-draw --no-first-run --no-margins --print-to-pdf-no-header --hide-scrollbars --ignore-certificate-errors --print-to-pdf='.$target_file.' '.$source_file;
We have the issue in the following environment:

OS: Ubuntu 22.04.2 LTS
Litespeed: 6.1
Web Host Essential (1-Worker) (LiteMage Starter)


The script works fine in AlmaLinux CLI and under Apache/PHP.

Kindly advice.

Regards,
Alex G.
 
#4
Now I see the first attempt to reserve a virtual memory space of 16 gigabytes completed fine, and the second and the third ones failed. So the chrome required more than 1 block of the virtual memory space of 16 gigabytes: 16 x 3 = 48G (at least are required).

Thanks.
 
Top