Skip to content

fix: exit when a PHP thread segfaults as PID 1 - #2595

Open
cyppe wants to merge 4 commits into
php:mainfrom
cyppe:agent/exit-on-fatal-signal-as-pid1
Open

cyppe wants to merge 4 commits into
php:mainfrom
cyppe:agent/exit-on-fatal-signal-as-pid1

Conversation

@cyppe

@cyppe cyppe commented Aug 7, 2026 •

Copy link
Copy Markdown

Summary

  • install a Linux-only SIGSEGV fallback before Go's runtime starts when FrankenPHP is PID 1
  • preserve any pre-existing non-default handler and leave non-PID-1 behavior unchanged
  • exit with status 2 when Go forwards a fatal fault from a C-created PHP thread
  • add a deterministic PID-namespace regression test with a timeout, so the previous runtime.raisebadsignal loop cannot hang the suite
  • explicitly enable the test's passwordless-sudo fallback in GitHub Actions, where unprivileged PID namespaces are restricted, so CI cannot silently skip the regression

The underlying signal-forwarding problem is golang/go#59569. This keeps the workaround local to FrankenPHP and avoids carrying a patched Go toolchain.

Closes #2558.

Verification

  • built the official Debian production runner target with Go 1.26.5 and PHP 8.4
  • go test -race -count=1 .
  • go test -race ./... in caddy/
  • TestCThreadSegfaultAsPID1 exits 2 instead of timing out
  • the same helper outside PID 1 is still terminated by SIGSEGV (shell status 139)

The focused test can be run after building the existing test helper:

cd internal/testcli
go build
cd ../..
go test -race -run '^TestCThreadSegfaultAsPID1$' -count=1 -v .

If unprivileged PID namespaces are disabled, opt into the same strict fallback used by CI:

FRANKENPHP_TEST_PID_NAMESPACE_WITH_SUDO=1 go test -race -run '^TestCThreadSegfaultAsPID1$' -count=1 -v .

@cyppe
cyppe marked this pull request as ready for review August 7, 2026 16:18
@cyppe

cyppe commented Nov 14, 2026

Copy link
Copy Markdown
Author

Merged the current main in (no force-push); the only conflict was two tests added at the same place in cli_test.go, both kept.

On the earlier red run: none of the failures came from this change. The static GNU builds failed compiling a third-party tls_o.c. The linux/386 job failed TestThreadDebugStateMetricsAfterRequests, and TestCThreadSegfaultAsPID1 was skipped there. The integration jobs were cancelled while installing the PHP development libraries.

Locally, in dunglas/frankenphp:builder-php8.4 (Go 1.27.4, PHP 8.4.27 ZTS) in a privileged container, TestCThreadSegfaultAsPID1 runs and passes, and go test -race . passes for the whole package. As per @dunglas's comment in #2558, the process now exits with status 2 instead of live-locking.

@dunglas dunglas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but another careful review by a maintainer would be very welcome :)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants