Opened 3 years ago
Last modified 12 months ago
#68817 assigned defect
php81-fpm: crashes constantly
| Reported by: | miken32 (Michael Newton) | Owned by: | ryandesign (Ryan Carsten Schmidt) |
|---|---|---|---|
| Priority: | Normal | Milestone: | |
| Component: | ports | Version: | |
| Keywords: | sonoma | Cc: | |
| Port: | php |
Description
This is a known issue I think since macOS 14 that affects a lot of software using fork() and Objective C libraries (or something like that, I am not a low-level programmer.)
objc[70634]: +[__SwiftNativeNSStringBase initialize] may have been in progress in another thread when fork() was called. objc[70634]: +[__SwiftNativeNSStringBase initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
There is an open ticket with PHP but it doesn't sound like it will get fixed anytime soon.
Workaround is setting an environment variable by changing the launch daemon to look like this:
<?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>Label</key><string>org.macports.php81-fpm</string> <key>ProgramArguments</key> <array> <string>/opt/local/bin/daemondo</string> <string>--label=php81-fpm</string> <string>--start-cmd</string> <string>/opt/local/sbin/php-fpm81</string> <string>;</string> <string>--pid=exec</string> </array> <key>Disabled</key><true/> <key>KeepAlive</key><true/> </dict> </plist>
This may be considered unsafe by some, so maybe it should be done as a variant?
Change History (4)
comment:1 Changed 3 years ago by ryandesign (Ryan Carsten Schmidt)
| Keywords: | sonoma added |
|---|---|
| Port: | php added; php-fpm removed |
| Summary: | PHP FPM crashes constantly → php81-fpm: crashes constantly |
comment:2 Changed 2 years ago by ryandesign (Ryan Carsten Schmidt)
Replying to miken32:
There is an open ticket with PHP but it doesn't sound like it will get fixed anytime soon.
Having now read that entire issue, the mentions there of gettext and the Foundation framework make me wonder updating to gettext 0.22.x helps, since gettext 0.22.x introduces the fix for a known crashing issue on Sonoma by linking with the Foundation framework.
comment:3 Changed 2 years ago by miken32 (Michael Newton)
Just a quick note to say that no, gettext 0.22 didn't help. I'm currently on gettext @0.22.5 (devel) and php83-fpm @8.3.6 (lang, www) with the same issue and resolution.
It pops up elsewhere as well, eg typing sudo ls / followed by Tab causes bash-completion to barf somehow (it's something to do with sudo; works fine otherwise.)
mike ~ ❱❱❱ sudo ls /objc[43923]: +[__SwiftNativeNSStringBase initialize] may have been in progress in another thread when fork() was called. objc[43923]: +[__SwiftNativeNSStringBase initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug. Abort trap: 6 Password:
comment:4 Changed 12 months ago by miken32 (Michael Newton)
Still having to do this workaround. I recently noted that pages where I had unintentionally used the _ function instead of Laravel's __ function for localization were causing the crash, even with the edit to the LaunchDaemon file. I was hoping PHP 8.4 might make a difference but it's MIA.
[04-Jun-2025 10:59:09.192207] DEBUG: pid 72727, fpm_log_open(), line 51: open access log (/opt/local/var/log/php83/access.log) [04-Jun-2025 10:59:09.192614] DEBUG: pid 72727, fpm_scoreboard_init_main(), line 38: got clock tick '100' [04-Jun-2025 10:59:09.192634] DEBUG: pid 72727, fpm_signals_init_main(), line 219: Unblocking all signals [04-Jun-2025 10:59:09.192668] DEBUG: pid 72727, fpm_socket_af_inet_socket_by_addr(), line 324: Found address for 127.0.0.1, socket opened on 127.0.0.1 [04-Jun-2025 10:59:09.192676] DEBUG: pid 72727, fpm_event_init_main(), line 354: event module is kqueue and 25 fds have been reserved [04-Jun-2025 10:59:09.192681] NOTICE: pid 72727, fpm_init(), line 83: fpm is running, pid 72727 [04-Jun-2025 10:59:09.192691] DEBUG: pid 72727, fpm_children_make(), line 449: blocking signals before child birth [04-Jun-2025 10:59:09.193064] DEBUG: pid 72727, fpm_children_make(), line 473: unblocking signals, child born [04-Jun-2025 10:59:09.193093] DEBUG: pid 72727, fpm_children_make(), line 479: [pool ramp] child 72728 started [04-Jun-2025 10:59:09.193103] DEBUG: pid 72727, fpm_children_make(), line 449: blocking signals before child birth [04-Jun-2025 10:59:09.193278] DEBUG: pid 72727, fpm_children_make(), line 473: unblocking signals, child born [04-Jun-2025 10:59:09.193304] DEBUG: pid 72727, fpm_children_make(), line 479: [pool ramp] child 72729 started [04-Jun-2025 10:59:09.193315] DEBUG: pid 72727, fpm_children_make(), line 449: blocking signals before child birth [04-Jun-2025 10:59:09.193490] DEBUG: pid 72727, fpm_children_make(), line 473: unblocking signals, child born [04-Jun-2025 10:59:09.193522] DEBUG: pid 72727, fpm_children_make(), line 479: [pool ramp] child 72730 started [04-Jun-2025 10:59:09.193532] DEBUG: pid 72727, fpm_children_make(), line 449: blocking signals before child birth [04-Jun-2025 10:59:09.193705] DEBUG: pid 72727, fpm_children_make(), line 473: unblocking signals, child born [04-Jun-2025 10:59:09.193732] DEBUG: pid 72727, fpm_children_make(), line 479: [pool ramp] child 72731 started [04-Jun-2025 10:59:09.193737] DEBUG: pid 72727, fpm_pctl_heartbeat(), line 478: heartbeat have been set up with a timeout of 30000ms [04-Jun-2025 10:59:09.193742] DEBUG: pid 72727, fpm_event_loop(), line 382: 14144 bytes have been reserved in SHM [04-Jun-2025 10:59:09.193745] NOTICE: pid 72727, fpm_event_loop(), line 383: ready to handle connections [04-Jun-2025 10:59:10.194837] DEBUG: pid 72727, fpm_pctl_perform_idle_server_maintenance(), line 398: [pool ramp] currently 0 active children, 4 spare children, 4 running children. Spawning rate 1 [04-Jun-2025 10:59:11.195810] DEBUG: pid 72727, fpm_pctl_perform_idle_server_maintenance(), line 398: [pool ramp] currently 0 active children, 4 spare children, 4 running children. Spawning rate 1 [04-Jun-2025 10:59:12.196968] DEBUG: pid 72727, fpm_pctl_perform_idle_server_maintenance(), line 398: [pool ramp] currently 0 active children, 4 spare children, 4 running children. Spawning rate 1 The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec(). Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug. [04-Jun-2025 10:59:12.627742] DEBUG: pid 72727, fpm_event_loop(), line 435: event module triggered 1 events [04-Jun-2025 10:59:12.627888] DEBUG: pid 72727, fpm_event_loop(), line 435: event module triggered 2 events [04-Jun-2025 10:59:12.627930] DEBUG: pid 72727, fpm_got_signal(), line 82: received SIGCHLD [04-Jun-2025 10:59:12.627941] DEBUG: pid 72727, fpm_event_loop(), line 435: event module triggered 1 events [04-Jun-2025 10:59:12.627949] WARNING: pid 72727, fpm_children_bury(), line 300: [pool ramp] child 72728 exited on signal 11 (SIGSEGV) after 3.434870 seconds from start

A quick Google search of
OBJC_DISABLE_INITIALIZE_FORK_SAFETYfinds results from years ago and that this environment variable and the OS feature it disables have been around since macOS High Sierra. But I've definitely run php-fpm under High Sierra and Catalina and Monterey. And you say this problem started for you in Sonoma. I wonder what changed in Sonoma.If the software crashes without adding the environment variable on Sonoma and later, then I think I should add it unconditionally on Sonoma and later to fix the crash rather than use a variant.