-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
php-fpm master processes runs 100% CPU and keeps spawning new ones #12157
Comments
Will try to give it a shot at some point with procfs in my own FreeBSD instance, I never needed nor used procfs (I do not need the Linux ABI layer). |
Sure. Appreciate you taking the time. I'm trying to track PID references in the debug log based on the original "master" PID and the children it's spawning. These "new" master processes could be children that are getting "killed" by the master, but don't fully exit. I don't need the Linux ABI layer either. It shouldn't be using it. Does needing procfs imply it's using / trying to use the Linux ABI layer??? I'll double check my poudriere build and config options. /var/run/php-fpm.pid (master PID file; 0644 perms) All process comms are via local sockets. /usr/local/etc/php-fpm.conf:
turning on "debug" and specifying "kqueue" ( I normally leave it to auto) are the only things I've changed from the configs I've been using for awhile. example pool config from the webman directory:
The snippet of the Apache config that calls it:
|
I can confirm the linux ABI layer is not enabled. I was puzzled by the need for procfs (native FreeBSD version) in/ etc/fstab:
as it has not ever been required. I figured it was something "new" in more recent PHP 8.1.x releases or something to do with 13.2 release. I have a 13.0 system with php8.1.6 that doesn't need it. |
I was just mentioning Linux compatilibilty layer because of the manpage. Activating procfs does not enable Linux however due to its deprecation, to me it seems this is the only use case left which really needs it. |
So I gave a go and procfs does not seem to affect that much the processes. Do you run it in jails ?
auto or kqueue does not matter, on freebsd auto uses kqueue. |
No, I don't use jails. It's all EC2 VMs. I thought the problem had gone away. It was fine for a few hours, but I checked this morning and the server is back to multiple root processes. However, I disabled procfs since you said it wasn't needed and switch back to "auto". I will enable I now see a few of these errors again:
if you're saying procfs shouldn't be used then I have no idea what's going on or why it would do that. |
Thanks. |
In the debug logs I can see these spawn as child pool processes:
that PID, |
I'm building PHP on a different box via a poudriere setup so I have a custom package repo for all my servers. procfs has never been enabled on it. Here are my 2 options file for php 8.1:
and
|
The poudriere config / build log is showing |
As a matter of fact no, this is the opposite on a typical freebsd setting without procfs mounted, it should not output it at all. |
I'm not aware of anything and my OPTIONS files aren't grepping anything. I've made no major changes to my builds since the spring and it worked fine until August or there abouts, but certainly some other package could have forced it on. |
I've added:
to my |
Looking at the poudriere source. The commits for that were in 2014 originally and I see no mention of recent changes, so I do think something changed in the php configure process perhaps for that to "flip" like that? |
So, I'm not seeing anymore proc errors, but still seeing the weird process. It's like it forks, but doesn't "finish" the fork or process "init" to flip over to the pool user.
then this new PID, ps aux shows it:
but the log after the
So, |
I have switched back to an old PHP 8.1.18 package, from /var/cache/pkg, which I had built April 14th which now also exhibits this behavior. This has me heavily leaning in the direction that something changed at the OS layer to make PHP act this way. Still no idea what that is or where to even start. I still also have no idea why /procfs needed a hard "NO" in poudriere when it's been working fine for 5+ years across FreeBSD 11.x, 12.x and 13.x up until now. I only use RELEASE and RELEASE-p* branches. EDIT: However, I see nothing in 13.2-RELEASE errata notices pointing at this, so it's also possible this is an issue that cropped up at release of 13.2 and I just didn't notice it due to low usage / dev ramp up of a few months to actually put loads on it. |
I ran ktrace and a kdump on the php-fpm process that is running hot and it's just looping with:
but I have no idea what that means, if anything. truss has similar output. |
those have trustworthy output in general indeed. If you think it comes from the system, did you try by any chance to fill a report in the FreeBSD's bugzilla tracker ? |
Yea, I put in a ticket there 9/27: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=274135 EDIT: Seems I spoke too soon. The problem took 2 days to surface again, but it did come back. So, ASLR is not the culprit. It seems FreeBSD's ASLR (default enabled in 13.2+) is to blame. I disabled it and no issues for the last 2 days. If nothing happens by Monday I'll see about escalating the issue...although not quite sure where to :) disabled ASLR by editing
|
So, after more Google-Fu...this issue seems to be caused by compiling ImageMagick or GraphicsMagick with OpenMP enabled. I re-built my ports tree and both servers that were having the problem exhibited no further issues in the last 10 days. see: https://lists.freebsd.org/archives/freebsd-apache/2022-November/000289.html So, I don't know if PHP should be responsible for still forking correctly or if it's FreeBSD problem or a OpenMP problem. @Mainteners. Close as you see fit. |
let's not close it, still worth keeping an eye. thanks for your reports. |
There are known issue with OpenMP and it is recommended to disable it. See a note about it in imagick docs. Reading the above it seems OpenMP somehow messes up the whole forking. I don't think we really want to fix this as OpenMP is not recommended by extension. I think packagers should rather make sure that PHP is not compiled with it. |
Description
We've been using php-fpm on FreeBSD since the PHP 7.x days and since FreeBSD 11.x and haven't seen this issue until starting to work with FreeBSD 13.2 . This issue does NOT present itself on older FreeBSD 13.0 systems with older versions of PHP 8.1.x
side note: since building for FreeBSD 13.2 I started seeing errors around needing procfs which I have now enabled. We never have had it enabled prior to this. I don't know if the issue is related. The 13.0 systems with earlier version of PHP8.1.x (circa .4) don't need procfs and throw no errors regarding it.
The issue we're seeing is that newer versions of PHP 8.1.18+ on FreeBSD 13.2 keep spawning new php-fpm master processes and they start running at 100% CPU. This happens within about an 30 minutes to an hour or so of PHP FPM being restarted. If I let it run for a few days I end up with 5 or 6 of them. I turned on FPM debug mode and the only line I'm seeing is:
[08-Sep-2023 13:44:17.388809] DEBUG: pid 4361, fpm_unix_init_main(), line 531: The calling process is waiting for the master process to ping via fd=9
[08-Sep-2023 13:44:27.404184] ERROR: pid 4361, fpm_unix_init_main(), line 559: the master process didn't send back its status (via the pipe to the calling process)
and then a little further down:
[08-Sep-2023 13:44:41.500023] DEBUG: pid 17136, fpm_unix_init_main(), line 531: The calling process is waiting for the master process to ping via fd=9
[08-Sep-2023 13:44:41.501321] DEBUG: pid 17580, fpm_scoreboard_init_main(), line 38: got clock tick '128'
[08-Sep-2023 13:44:41.501430] DEBUG: pid 17580, fpm_signals_init_main(), line 219: Unblocking all signals
[08-Sep-2023 13:44:41.501967] DEBUG: pid 17580, fpm_event_init_main(), line 354: event module is kqueue and 1 fds have been reserved
[08-Sep-2023 13:44:41.502024] NOTICE: pid 17580, fpm_init(), line 83: fpm is running, pid 17580
[08-Sep-2023 13:44:41.502030] DEBUG: pid 17580, main(), line 1844: Sending "1" (OK) to parent via fd=10
[08-Sep-2023 13:44:41.502049] DEBUG: pid 17136, fpm_unix_init_main(), line 550: I received a valid acknowledge from the master process, I can exit without error
[08-Sep-2023 13:44:41.507431] DEBUG: pid 17580, fpm_pctl_heartbeat(), line 478: heartbeat have been set up with a timeout of 3333ms
[08-Sep-2023 13:44:41.507461] DEBUG: pid 17580, fpm_event_loop(), line 382: 190480 bytes have been reserved in SHM
[08-Sep-2023 13:44:41.507467] NOTICE: pid 17580, fpm_event_loop(), line 383: ready to handle connections
and that seems accurate, timewise, after the last restart. I don't know if any specific request is triggering this. We run sites through dedicated "site" pools. So, each site gets its own dedicated php-fpm "pool" user. They seem to spawn and die fine and sites still work until eventually we'll run into "max pool" issues due to all the master-processes running.
Let me know what additional information might be helpful.
PHP Version
8.1.23
Operating System
FreeBSD 13.2-p3
The text was updated successfully, but these errors were encountered: