-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
segmentation fault when sending SIGINT to PHP embedded in another program #9649
Comments
There is a good chance that the signal handler is being invoked on a thread that didn't execute PHP. In this case, per-thread resources have not been initialized on the thread, so I can reproduce the issue with this: https://gist.github.com/arnaud-lb/d0f2282e66def91a6ee34e1537b3ac5f I'm assuming that there is no way to install hooks in Go's thread creations. One way to prevent this crash would be to mask all signals in all threads except the ones that are ready to handle signals. An other way would be to disable ZEND_SIGNAL entirely ( |
Thank you very much for your help @arnaud-lb. I confirm that disabling I also tried to mask all signals: https://gist.github.com/dunglas/278225a71ba3fc11a27ca8c1705fa0c8 This fixes the problem in your reproducer, unfortunately, it doesn't play very well with the Go embedding use case because it's not desirable (and probably not possible at all) to change the mask for threads started by Go itself. Couldn't we detect if it's a thread executing PHP before calling |
We could detect it at least to avoid the crash. I'm not sure we could do anything else than returning from the signal handler, though.
If it was possible to set the mask before Go starts any thread (or before Go itself starts), it would be inherited by all threads. It would only be required to mask the signals listed here: Line 74 in 69e6a94
|
Looks like this might be the stack overflow I was seeing in #8029
|
Description
I'm embedding PHP in a Go program. When this program receives
SIGINT
, PHP crashes with the following stack trace (extracted using GDB):This may be related to #8029, #8789, #9337.
If anyone has an idea of what's happening, I can give them access to a private repository with a simple way to reproduce the crash. I reproduced the issue on Debian and macOS.
Go documentation about signal handling and C code: https://pkg.go.dev/os/signal#hdr-Go_programs_that_use_cgo_or_SWIG
PHP Version
PHP 8.2-dev
Operating System
Debian, macOS
The text was updated successfully, but these errors were encountered: