oerdnj / deb.sury.org

Public bugreports for anything ppa:ondrej/*
821 stars 25 forks source link

php-fpm segmentation fault when sending the reload signal to php-fpm in a Docker container #1485

Open claude-vessaz-hs opened 3 years ago

claude-vessaz-hs commented 3 years ago

Frequently asked questions

Describe the bug php-fpm receives a SIGSEV when a reload signal (kill -HUP <pid>) is sent to any of the php-fpm processes. So far, I was only able to reproduce this behaviour in a docker container. I was able to reproduce the error in a debug container:

(16:02 0fd9a2343028:/ebs1/www) gdb /usr/sbin/php-fpm7.0
GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/sbin/php-fpm7.0...Reading symbols from /usr/lib/debug/.build-id/9c/f28673850581d357ef1693f98fdd02117c208c.debug...done.
done.
(gdb) r --fpm-config /etc/php/7.0/fpm/php-fpm.conf
Starting program: /usr/sbin/php-fpm7.0 --fpm-config /etc/php/7.0/fpm/php-fpm.conf
warning: Error disabling address space randomization: Operation not permitted
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[27-Nov-2020 16:03:48] NOTICE: fpm is running, pid 126
[27-Nov-2020 16:03:49] NOTICE: ready to handle connections
[27-Nov-2020 16:03:49] NOTICE: systemd monitor interval set to 10000ms

Program received signal SIGSEGV, Segmentation fault.
fpm_event_select_wait (queue=<optimized out>, timeout=<optimized out>) at ./sapi/fpm/fpm/events/select.c:120
120 ./sapi/fpm/fpm/events/select.c: No such file or directory.
(gdb) bt
#0  fpm_event_select_wait (queue=<optimized out>, timeout=<optimized out>) at ./sapi/fpm/fpm/events/select.c:120
#1  0x0000564b4b2fe439 in fpm_event_loop (err=err@entry=0) at ./sapi/fpm/fpm/fpm_events.c:416
#2  0x0000564b4b2f8c07 in fpm_run (max_requests=0x7ffef3d1a85c) at ./sapi/fpm/fpm/fpm.c:115
#3  0x0000564b4b0dd311 in main (argc=3, argv=0x7ffef3d1ae78) at ./sapi/fpm/fpm/fpm_main.c:1881

This started happening after the latest upgrade of php7.0-fpm (and a bunch of other packages) to the -37 version. We did not observe this behaviour in previous versions (-34 and lower). It was not able to reproduce the behaviour by just installing php-fpm, so I suspect it is related to one of our extensions, but I was not able to narrow it down yet which one.

While this bug-report is about PHP 7.0, it affects 7.3 as well, but I can't say for sure if it was introduced recently in the 7.3 version.

To Reproduce I unfortunately was only able to reproduce it in a container depending on internal resources so far and I could not narrow down what extension is causing this. I am currently working on a container which only depends on public resources and will comment in the issue as soon I have a Dockerfile avilable.

In a nutshell:

  1. Start php-fpm process
  2. Send reload signal (kill -HUP <any php-fpm pid>
  3. Observe segfault

Expected behavior php-fpm should reload without a segfault.

Distribution (please complete the following information):

Package(s) (please complete the following information):

php7.0-fpm
php7.0-bcmath
php7.0-cli
php7.0-gd
php7.0-mysql
php7.0-curl
php7.0-dev
php7.0-apcu
php7.0-apcu-bc
php7.0-gearman
php7.0-geoip
php7.0-intl
php7.0-memcached
php7.0-mongodb
php7.0-mbstring
php7.0-oauth
php7.0-redis
php7.0-xdebug
php7.0-xml
php7.0-zip
php7.0-zmq
grpc-1.25.0 from pecl
protobuf from https://github.com/hootsuite/php-protobuf
maxmind-db-reader-1.6.0 from https://github.com/maxmind/MaxMind-DB-Reader-php
claude-vessaz-hs commented 3 years ago

I was finally able to narrow this down and create a "simple" Dockerfile for reproduction: https://gist.github.com/claude-vessaz-hs/7cf49137435db2036eaa70d318e27a2e

Full reproduction steps:

  1. Copy both files from gist into directory
  2. Open path in terminal
  3. docker build -t php-fpm70:segfault .
  4. docker run --rm --name segfault php-fpm70:segfault
  5. Open a new terminal window and exec into container: docker exec -it segfault bash
  6. Look up PID of php-fpm process (ps aux)
  7. Send reload command: kill -HUP <pid>
  8. Container should exit with a segfault

The issue boils down to events.mechanism = select in the php-fpm config. We have this enabled. If the line is commented out, the php-fpm process reloads fine.

I was not able to install an older version of php-fpm and see if it really was introduced with the latest update.