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.

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