Skip to content

fix: keep Go's preemption signal off the PHP threads - #2833

Open
nicolas-grekas wants to merge 1 commit into
php:mainfrom
nicolas-grekas:fix-preemption-signal
Open

nicolas-grekas wants to merge 1 commit into
php:mainfrom
nicolas-grekas:fix-preemption-signal

Conversation

@nicolas-grekas

Copy link
Copy Markdown
Contributor

The Go runtime preempts goroutines with SIGURG, sent to the thread that runs them. A PHP thread runs Go code during each callback, and the signal may only land once the thread is back in PHP and entering a system call, which then fails with EINTR: stream_select() returns false with a warning, Io\Poll\Context::wait() throws a FailedPollWaitException.

I get one interrupted wait in 240k when a script follows tasks through a poll context (#2636), and none with GODEBUG=asyncpreemptoff=1.

Blocking the signal when the thread starts doesn't hold: Go unblocks it at the first call into Go. Blocked after that call, it stays blocked, since the thread keeps its M. The Go code of a PHP thread is then preempted at its safe points only, which its callbacks reach quickly.

The Go runtime preempts goroutines with SIGURG, sent to the thread that
runs them. A PHP thread runs Go code during each callback, and the signal
may only land once the thread is back in PHP and entering a system call,
which then fails with EINTR: stream_select() returns false with a warning,
a poll context throws.

Blocking the signal when the thread starts does not hold, Go unblocks it at
the first call into Go. Blocked after that call, it stays blocked, since
the thread keeps its M.

@henderkes henderkes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm starting to understand why everyone hates Cgo. I wish there was a long-term solution to all these Go runtime things without kicking the project into manual go library build mode.

henderkes added a commit that referenced this pull request Nov 16, 2026
…04 (#2834)

`ubuntu-latest` is now Ubuntu 26.04, where nine jobs fail on every PR
(see the checks of #2833):

- "Integration Tests": GCC 14+ rejects the generated extensions. cgo
includes `<stdlib.h>` before `php.h`, so they now define `_GNU_SOURCE`
as `cgo.go` does, and nullable `int` and `bool` arguments point to
values of the types cgo declares.
- "Tests" abort at the second `phpinfo()` of the process: PHP unloads
shared extensions when it shuts down, and libenchant 2.8 can't be loaded
twice, GObject still knows its types. The PHP of the CI jobs no longer
loads enchant.
- "msan": MemorySanitizer in clang 21 takes the index of
`_mm512_permutex2var_epi8()` for uninitialized memory (fixed in clang 22
by llvm/llvm-project#148785). The sanitizer jobs now use clang 22, which
Ubuntu 26.04 has in its archive.

The enchant abort is not only a CI matter: on such a system, a server
dies at the first use of enchant after a worker restart, an
`opcache_reset()` or a config reload. Setting `ZEND_DONT_UNLOAD_MODULES`
from FrankenPHP avoids it, and #2730 too, but I left that out: net-snmp
doesn't expect to be initialized twice, it floods the log at each start
and the suite segfaults on the runner.

---------

Signed-off-by: Marc <m@pyc.ac>
Co-authored-by: Marc <m@pyc.ac>

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

Development

Successfully merging this pull request may close these issues.

3 participants