php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80024 Duplication of info about inherited socket after pool removing
Submitted: 2020-08-27 04:30 UTC Modified: 2021-02-28 21:16 UTC
From: syazov at plesk dot com Assigned: bukka (profile)
Status: Closed Package: FPM related
PHP Version: 7.4.9 OS: All Unix
Private report: No CVE-ID: None
 [2020-08-27 04:30 UTC] syazov at plesk dot com
Description:
------------
"FPM_SOCKETS_X" env variable isn't cleaned when it's become unused.
The issue is appeared if count of sockets is changed from "FPM_ENV_SOCKET_SET_SIZE * n + 1" to "FPM_ENV_SOCKET_SET_SIZE * n"
In such cases the same socket presents in "FPM_SOCKETS_[socket_set_count - 1]" and "FPM_SOCKETS_[socket_set_count]"
       

Test script:
---------------
#!/bin/bash -xe

# all paths are specific to default ones in Ubuntu 20.04
pool_d="/etc/php/7.4/fpm/pool.d"
pool_0="$pool_d/www.conf"
sed -i "s/^pm = dynamic$/pm = ondemand/" "$pool_0"
for i in {1001..1128}; do
    pool_i="$pool_d/www_$i.conf"
    cp -p "$pool_0" "$pool_i"
    sed -i "s/^\[www\]$/\[www_$i\]/" "$pool_i"
    sed -i "s|^listen = /run/php/php7.4-fpm.sock$|listen = /run/php/php7.4-fpm.$i.sock|" "$pool_i"
done
systemctl restart php7.4-fpm

rm -f "$pool_d/www_1001.conf"
systemctl reload php7.4-fpm
systemctl reload php7.4-fpm

Expected result:
----------------
php-fpm reloads successfully.

Actual result:
--------------
"503 Service Unavailable" is shown

```
ls: cannot access '/run/php/php7.4-fpm.1128.sock': No such file or directory
```

```
[27-Aug-2020 10:31:00] NOTICE: reloading: execvp("/usr/sbin/php-fpm7.4", {"/usr/sbin/php-fpm7.4", "--nodaemonize", "--fpm-config", "/etc/php/7.4/fpm/php-fpm.conf"})
[27-Aug-2020 10:31:02] NOTICE: using inherited socket fd=7, "/run/php/php7.4-fpm.sock"
[27-Aug-2020 10:31:02] NOTICE: using inherited socket fd=135, "/run/php/php7.4-fpm.1128.sock"
[27-Aug-2020 10:31:02] NOTICE: using inherited socket fd=9, "/run/php/php7.4-fpm.1002.sock"
...
[27-Aug-2020 10:31:02] NOTICE: using inherited socket fd=134, "/run/php/php7.4-fpm.1127.sock"
[27-Aug-2020 10:31:02] NOTICE: using inherited socket fd=135, "/run/php/php7.4-fpm.1128.sock"
[27-Aug-2020 10:31:02] ERROR: epoll: unable to add fd 135
```

Patches

fix-inherited-socket-duplication-on-reload.patch (last revision 2020-08-27 04:32 UTC by syazov at plesk dot com)

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-08-27 04:32 UTC] syazov at plesk dot com
The following patch has been added/updated:

Patch Name: fix-inherited-socket-duplication-on-reload.patch
Revision:   1598502740
URL:        https://bugs.php.net/patch-display.php?bug=80024&patch=fix-inherited-socket-duplication-on-reload.patch&revision=1598502740
 [2020-12-28 21:42 UTC] bukka@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: bukka
 [2020-12-28 21:42 UTC] bukka@php.net
Ah good catch. The patch makes sense. Just detail that it doesn't contain your email (it's more a diff) so do you want to use this email address as a commiter? Or if you could create a github PR, that would be even better.
 [2020-12-29 03:08 UTC] syazov at plesk dot com
The following pull request has been associated:

Patch Name: Fix bug #80024: prevent duplication of inherited sockets on reload
On GitHub:  https://github.com/php/php-src/pull/6550
Patch:      https://github.com/php/php-src/pull/6550.patch
 [2020-12-29 03:10 UTC] syazov at plesk dot com
Done, PR#6550 was created and linked.
 [2021-01-30 20:55 UTC] bukka@php.net
Hmm so I managed to put together a test for this in fpmi but was not able to make it fail for this case. So I also tried your script (I'm on Ubuntu 20.04 as well) and it also doesn't fail. Is that test script actually working for you?

I noticed that you use ondemand so how can this actually fail when no children are running. I guess I might need to ping the pools at least to create children. Will take a look into this more later but if you can provide something more re-creatable in the meantime, that would be appreciated.
 [2021-02-18 11:23 UTC] syazov at plesk dot com
Sorry for long silence.
I rechecked the script and found out that it could fail sometimes so I added some delay after reloads and the error became visible stably.
```
+ rm -f /etc/php/7.4/fpm/pool.d/www_1001.conf
+ date
Thu Feb 18 18:18:52 +07 2021
+ systemctl reload php7.4-fpm
+ systemctl reload php7.4-fpm
+ date
Thu Feb 18 18:18:52 +07 2021
+ sleep 5
+ grep ERROR /var/log/php7.4-fpm.log
[18-Feb-2021 18:18:56] ERROR: epoll: unable to add fd 135
```
 [2021-02-28 21:16 UTC] bukka@php.net
Thanks I managed to recreate it and also put together a test that was failing before the change and after applying it, it's passing.
 [2021-02-28 21:17 UTC] bukka@php.net
The following pull request has been associated:

Patch Name: FPM: Fix duplication of inherited sockets on reload
On GitHub:  https://github.com/php/php-src/pull/6740
Patch:      https://github.com/php/php-src/pull/6740.patch
 [2021-03-21 18:52 UTC] bukka@php.net
Automatic comment on behalf of bukka
Revision: http://git.php.net/?p=php-src.git;a=commit;h=c483b59124bda89f86d8a54bcbdb8e5b89fa40ea
Log: Fix bug #80024: Duplication of info about inherited socket after pool removing
 [2021-03-21 18:52 UTC] bukka@php.net
-Status: Assigned +Status: Closed
 [2021-03-21 19:00 UTC] bukka@php.net
Automatic comment on behalf of bukka
Revision: http://git.php.net/?p=php-src.git;a=commit;h=c483b59124bda89f86d8a54bcbdb8e5b89fa40ea
Log: Fix bug #80024: Duplication of info about inherited socket after pool removing
 [2021-03-21 19:01 UTC] bukka@php.net
Automatic comment on behalf of bukka
Revision: http://git.php.net/?p=php-src.git;a=commit;h=c483b59124bda89f86d8a54bcbdb8e5b89fa40ea
Log: Fix bug #80024: Duplication of info about inherited socket after pool removing
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC