-
-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Apple segfaults when php-fpm scripts invoke gettext #137431
Comments
@carlocab could this be related to your recent changes? |
Maybe? Hard to say without a backtrace. |
@Saeven, could you try doing
and see if that helps? |
I'm having a similar issue as well, though not related to gettext. In my case, any query to the database using That being said, using php built-in server, everything seems to be working as usual. The code snippets by @carlocab seems to fix the issue. Thanks a heap @carlocab |
It's really more of a workaround rather than a fix. We should figure out what's going wrong and fix it properly, as that workaround is going to stop working at some point. |
I agree as well. I would like to take a stab on finding the cause of this issue if I can get some guidance. It's my first time dealing with homebrew or package manager in general. I saw that you mentioned a backtrace. How would one do a backtrace? |
Here to help if you need a backtrace; truth is I spent a few minutes trying to get one for myself but the darned thing won't dump.
And then in the config area:
Anything I've missed? |
I am having the same issue as Saeven. Tried to reinstall php using the suggestion here and it still fails with the same error logs. `[25-Jul-2023 15:34:36] NOTICE: fpm is running, pid 88426 [25-Jul-2023 15:34:36] NOTICE: ready to handle connections [25-Jul-2023 15:35:51] WARNING: [pool www] child 88428 exited on signal 6 (SIGABRT) after 74.611026 seconds from start [25-Jul-2023 15:35:51] NOTICE: [pool www] child 89954 started [25-Jul-2023 15:36:23] WARNING: [pool www] child 88429 exited on signal 9 (SIGKILL) after 106.788182 seconds from start [25-Jul-2023 15:36:23] NOTICE: [pool www] child 90238 started [25-Jul-2023 15:36:28] WARNING: [pool www] child 88431 exited on signal 6 (SIGABRT) after 111.407527 seconds from start [25-Jul-2023 15:36:28] NOTICE: [pool www] child 90309 started [25-Jul-2023 15:41:24] WARNING: [pool www] child 88430 exited on signal 6 (SIGABRT) after 408.270930 seconds from start [25-Jul-2023 15:41:24] NOTICE: [pool www] child 92347 started` |
@Saeven @jonquihote @joshbyvelds Related this #137909 (comment) Could you add following code to your
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EnvironmentVariables</key>
<dict>
<key>OBJC_DISABLE_INITIALIZE_FORK_SAFETY</key>
<string>YES</string>
</dict>
<key>KeepAlive</key>
<true/>
<key>Label</key> I'm using Laravel Valet and tested like this:
mkdir ~/Sites/testsite
vi ~/Sites/testsite/index.php inside <?php
echo gettext("hello");
|
None of the previous posts talks about |
@SMillerDev Laravel Valet uses |
@askdkc Editing the the startup task with those parameters, so far, does eliminate the segfault being experienced. No Laravel here (Laminas!) - but in an nginx+php-fpm stack it allows the script to run. 🎉 |
Laravel Valet is just a service wrapper which does manage nginx, php and dnsmasq services using homebrew services behind the scene to setup php environment. So it is actually all related with homebrew packages and services. (just php in this case). So far we found out that running Why this happen?Apple used to allow these process to run just logging warnings to the log. It was perfectly fine until Apple decided to kill it. Did homebrew screw things up? No. Homebrew did nothing wrong. How about Linux? Does it kill php fork process? No. Does adding Did your php code ever kill your OS using php-fpm? Your entire system? No. (Well, if you screw up with your php code really bad, it might be?) So it was like php-fpm was running with Only Apple who decided to kill it. Linux: "this is fine. Keep going." Meanwhile php developers using macOS have tough time on this. Until it gets fixed by php upstream, Homebrew adding this environment variable to its php startup script is really providing nice iced water for people in the living hell. I mean, it's usually Mac people using Homebrew. Linux has their own distoro's package manager. Using homebrew for linux is unlikely. Homebrew providing Mac only work-around to its package does sound like it should be. (But of course, upstream fix is ideal. This is just temporary. Please revert this fix after it gets fixed by upstream) |
TLDR; Someone at Apple said "Fork those guys!" ;) |
In my Intel Mac the file path is /usr/local/Cellar/php/8.2.8/homebrew.mxcl.php.plist. |
Thank you for your effort! Could you do me another favor? Sometimes, people get two
If you have both files, could you remove
Then restart your Mac. And see if it fixes the problem or not? |
Same as @picov. My: Intel Mac + Monterey + php8.2 + valet + postgresql I confirmed:
But the problem is the same (nginx 502). I have read your all comments in laravel/valet#1433. But it's not solved this problem that has been bothering me for 3 days, can't work. What information can I provide to help solve it?
|
If you are using Valet with PostgreSQL like me, try this mattstauffer comment instruction: laravel/valet#1433 (comment) Perhaps the key point is Delete the See how it goes. Good luck! |
I've just verified that in my M1 installation the file inside I've reconfigured Apache to use PHP as FastCGI/FPM mode (previously it was configured as module in Apache 2 handler mode), edited the file above and restarted the service (and Mac also). On an Intel Mac the problem is the same. |
Interesting. How about try brew services stop php
rm ~/Library/LaunchAgents/homebrew.mxcl.php.plist
sudo brew services start php Does it make difference? Or if it's particular |
Yes, it make difference! If PHP is configured as Apache module (Server API: Apache 2.0 Handler) to solve the problem there is the need to start even httpd as root (sudo brew services start httpd). PS: the _ gettext walkaround with putenv doesn't work. |
Great! It's nice to see you solved the problem. Congrats! And it looks like Apache is doing somewhat better job than Nginx in this case. Interesting.
Is your <key>EnvironmentVariables</key>
<dict>
<key>OBJC_DISABLE_INITIALIZE_FORK_SAFETY</key>
<string>YES</string>
</dict> If so, your |
My "/opt/homebrew/Cellar/php/8.2.8_1/homebrew.mxcl.php.plist" and my "/Library/LaunchDaemons/homebrew.mxcl.php.plist" not have the OBJC_DISABLE_INITIALIZE_FORK_SAFETY parameter. |
Thank you for checking. |
I have tried the above, but it didn't work. Later, when I was discouraged, I finally thought that this might be a system-related problem, so I tried to upgrade the system to Mac Ventura 13.5. Currently anyway thank you! |
Wow!! It's nice to see you finally get it working👍 Congrats!! |
Reading GitHub comment doesn't give you an actual number of users who has problem. C'mon. |
If fixing an env var that gettext uses solves gettext from crashing upstream, then that suggests there's a bug in gettext. |
What makes the krb5 package a dependency to php? What's it providing? What's lost if it's dropped? What alternatives exist? |
Being a full time PHP developer and follower of various related news sources with no mention of this problem anywhere but in this issue gives me an idea though. |
What makes the krb5 package a dependency to php? Kerberos support in the curl, MySQL and IMAP implementations
Leaving PHP users with broken/incomplete cURL, MySQL and IMAP implementations |
Laravel Valet (php-fpm) is working fine with MySQL on this issue which is kinda irony. Using with PostgreSQL or mongodb are having this problem. BTW Laravel Herd uses Valet under the hood that doesn't have this problem. Herd uses its own php static binary though. Docker also doesn't have this issue. I wonder why the Homebrew version only has this issue. |
The docker one can't use any system libraries and the static binary probably compiles in a copy of all system libraries so they can't triggers Apple's fork protections like Homebrew's dependency on system components does. |
Yeah, do we really need to follow Apple way? Is it worth? No matter how hard we try, they will just keep changing their rules (like this sudden killing fork process change). I mean if you can fix it soon that's fine but if this remains the same for long time, it's just bad. |
On macOS there is no other way. Apple makes the OS, it gets to decide how it works.
Just to clarify, this is a protection that Apple enabled to avoid programs making potentially devices destroying mistakes.
While I agree it's bad, the only thing Homebrew can do is ship a service that disables the protections. The real fixing has to be done by the developers of either PHP or the MongoDB/Postgres implementations that are failing, so this thread isn't going to bring much difference in the long run. |
> What makes the krb5 package a dependency to php?
Kerberos support in the curl, MySQL and IMAP implementations
What alternatives exist?
Leaving PHP users with broken/incomplete cURL, MySQL and IMAP
Can we (someone) try an altered php build formula that excludes Kerberos as a proof of concept to diagnose that this issue lies in that dependency?
And then maybe even try an older version of it as a second layer of testing?
|
You can just do this by following these steps:
brew reinstall php.rb --build-from-source FYI: PHP without kerberos still gives you 502. And if you want to revert your PHP to normal version, just run brew reinstall php |
@askdkc I'm thinking that that's probably because the other packages that are actually crashing are also using the various updates that Homebrew has published since the same time when krb5 was updated. Rolling back git on the homebrew-core tap to June 19 or 20 may be what's needed in order to do a cleaner simulation. But that would only be useful for confirming where the problem lies ... and if the problem is already confirmed to be changes incorporated into krb5 1.21 then the only benefit to tinkering with homebrew's build would be in the replacement of krb5 with some alternative ... which may or may not help if the related packages that are crashing are crashing because of krb5 too. That said, given the updates posted by Ken Hornstein and krb5 maintainer Greg Hudson, I wonder if time would be better spent exploring their suggestions:
Is "work around this problem in configuration" something that can be done in the PHP build? Or even post-build as an env var or an .ini setting? Unfortunately I'm at the edge of my understanding on how to "do" this. So I'm now just asking questions to help bring up ideas with which someone with more applied knowledge of this may arrive at a solution. |
If it is Postgres that's the problem, there's |
For me setting |
Following @dentarg advice, I've finally found a solution that works for Postgres even after a reboot. Although this still errors with In
Add an environment variable like this:
Then restart php. This will work even after a reboot. Tested this working in php 8.2 and 7.4. UPDATE: If you're using laravel/valet the file should be |
For me on Apple M2 also adding |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
This topic is not stale. The problem is still prominent. |
There seem to be multiple fixes, but none would work as a patch for Homebrew. |
After initially resolving this issue by (I think) adding OBJC_DISABLE_INITIALIZE_FORK_SAFETY key to the plist file, I'm encountering it again. But, if I disable Wifi everything works fine. When Wifi is on (connected to corporate Wifi or hotspot) it does not. I think I've tried everything that's detailed in this thread. Apple M1 Pro Any help appreciated, it's driving me mad! |
signal 11
As soon as I do If I start PHP as root it works as expected:
Edit: Also setting |
Ref my previous post above - #137431 (comment) This worked for me: Add the following lines to your
And restart your effected PHP service, or test in running it directly: /usr/local/opt/php@8.4/sbin/php-fpm --nodaemonize Needed this on all mine PHP versions, to make it work:
|
I've had this problem on my dev Mac (M1) Version 14.0 of a 502 error from nginx when accessing postgres database using php in a symfony app. All three (php, nginx, postgres) are standard homebrew installs. php-fpm.log entry: [pool www] child 65967 exited on signal 11 (SIGSEGV) after 1372.087190 seconds from start The fix by @steinmb has got things working again. |
For me this started happening after my intel iMac automatically upgraded to MacOS 14 Sonoma. Or I can't remember exactly in what order things happened, but I at least upgraded homebrew after the automatic OS upgrade due to homebrew complaining about an unknown OS version and I'm running MySQL, PHP, nginx, and every single of my PHP projects are Drupal projects. This error was happening consistently, but on so few pages I was ignoring it for a while, but when it finally bothered me enough to investigate I tracked it down to a I want to say that out of all the proposed solutions here the
One thing I will note is that adding At least it seems to work again now, and without me needing to manually alter each script/project, or run services as sudo 🤞 I also have an M1 Macbook at work with a pretty identical setup. I'll double check that tomorrow, and see if I'm seeing this problem there or not. Edit: Same problem on my M1 Macbook, but there just restarting PHP after doing #137431 (comment) worked. I only need to add |
brew gist-logs <formula>
link ORbrew config
ANDbrew doctor
outputVerification
brew doctor
output" saysYour system is ready to brew.
and am still able to reproduce my issue.brew update
and am still able to reproduce my issue.brew doctor
and that did not fix my problem.What were you trying to do (and why)?
PHP installs without issue, however, after installation any script that invokes gettext causes a crash. I'm unable to get a core for some reason, but I've isolated the issue to gettext.
Can confirm that it works on my old Intel Mac, but not on the M2 (mine) or that of a colleague (same CPU).
Create a script that contains:
Try to access the script via php-fpm and you get a bad gateway with a segfault in logs. Curiously, accessing via CLI produces the expected output.
What happened (include all command output)?
saeven@SaevenStudio ~ % sudo /opt/homebrew/opt/php/sbin/php-fpm --nodaemonize
Password:
[24-Jul-2023 15:53:20] NOTICE: fpm is running, pid 19583
[24-Jul-2023 15:53:20] NOTICE: ready to handle connections
[24-Jul-2023 15:53:30] WARNING: [pool www] child 19584 exited on signal 11 (SIGSEGV) after 9.763474 seconds from start
[24-Jul-2023 15:53:30] NOTICE: [pool www] child 19587 started
What did you expect to happen?
No segfaults on access.
Step-by-step reproduction instructions (by running
brew
commands)The text was updated successfully, but these errors were encountered: