Skip to content

Fix GH-10437: Set active fiber to null on bailout #10443

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

Merged
merged 1 commit into from
Jan 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ PHP NEWS
. Fixed overflow check in OnUpdateMemoryConsumption. (nielsdos)
. Fixed bug GH-9916 (Entering shutdown sequence with a fiber suspended in a
Generator emits an unavoidable fatal error or crashes). (Arnaud)
. Fixed bug GH-10437 (Segfault/assertion when using fibers in shutdown
function after bailout). (trowski)

- FFI:
. Fixed incorrect bitshifting and masking in ffi bitfield. (nielsdos)
Expand Down
18 changes: 18 additions & 0 deletions Zend/tests/fibers/gh10437.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
GH-10437 (Segfault/assertion when using fibers in shutdown function after bailout)
--FILE--
<?php

register_shutdown_function(function (): void {
var_dump(Fiber::getCurrent());
});

$fiber = new Fiber(function (): never {
trigger_error('Bailout in fiber', E_USER_ERROR);
});
$fiber->start();

?>
--EXPECTF--
Fatal error: Bailout in fiber in %sgh10437.php on line %d
NULL
1 change: 1 addition & 0 deletions Zend/zend_fibers.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ static zend_always_inline zend_fiber_transfer zend_fiber_switch_to(

/* Forward bailout into current fiber. */
if (UNEXPECTED(transfer.flags & ZEND_FIBER_TRANSFER_FLAG_BAILOUT)) {
EG(active_fiber) = NULL;
zend_bailout();
}

Expand Down