-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Segfault when using ReflectionFiber #11121
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
Comments
Thank you! I can reproduce this. Interestingly, I also get errors in |
Precisely my problem as well, was hoping someone here could make more sense of it :) |
I tried to debug this for a bit now. Look like |
The root cause is the fiber->execute_data not being updated when a fiber is switched from due to resumption of another fiber. Essentially, it's pointing to memory in the middle of its VM stack. This non-crashing example, but having the wrong output illustrates the issue:
A crashing example (by stack spraying with that max() call):
However, I'm not sure what the proper fix would be:
I'd prefer the latter for master. For the current branches, we probably have to just special case zend_ce_fiber in zend_fiber_switch_context: diff --git a/Zend/zend_fibers.c b/Zend/zend_fibers.c
index 53f78417f5..6f55455190 100644
--- a/Zend/zend_fibers.c
+++ b/Zend/zend_fibers.c
@@ -395,6 +395,10 @@ ZEND_API void zend_fiber_switch_context(zend_fiber_transfer *transfer)
zend_observer_fiber_switch_notify(from, to);
+ if (from->kind == zend_ce_fiber) {
+ zend_fiber_from_context(from)->execute_data = EG(current_execute_data);
+ }
+
zend_fiber_capture_vm_state(&state);
to->status = ZEND_FIBER_STATUS_RUNNING; Maybe someone else has a better idea? |
Imo the plan for stable branches, and the plan (the last one, which is also your preference) for master sound good. |
Ping, could anyone merge the suggested fix? :) |
Description
The following code: https://paste.daniil.it/segfault_reflectionfiber_v2.tar.xz (all dependencies are exactly the ones specified in composer.lock, with a few manual patches made to
vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php
,vendor/danog/madelineproto/src/GarbageCollector.php
to enable ReflectionFiber logging; use API ID and API hash1
,1
to test)Resulted in a segfault with this gdb backtrace:
zbacktrace doesn't work.
But I expected this output instead: No segfault
PHP Version
8.2.5
Operating System
Arch linux
The text was updated successfully, but these errors were encountered: