Skip to content

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

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

fix: exit when a PHP thread segfaults as PID 1#2595
cyppe wants to merge 2 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant