-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add API to prevent Fiber switch in select contexts
Co-authored-by: Martin Schröder <m.schroeder2007@gmail.com>
- Loading branch information
Showing
16 changed files
with
237 additions
and
156 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--TEST-- | ||
Cannot resume fiber within destructor | ||
--FILE-- | ||
<?php | ||
|
||
$fiber = new Fiber(function () { | ||
Fiber::suspend(); | ||
}); | ||
$fiber->start(); | ||
|
||
return new class ($fiber) { | ||
private $fiber; | ||
|
||
public function __construct(Fiber $fiber) { | ||
$this->fiber = $fiber; | ||
} | ||
|
||
public function __destruct() { | ||
$this->fiber->resume(1); | ||
} | ||
}; | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Uncaught FiberError: Cannot switch fibers in current execution context in %sno-switch-dtor-resume.php:%d | ||
Stack trace: | ||
#0 %sno-switch-dtor-resume.php(%d): Fiber->resume(1) | ||
#1 %sno-switch-dtor-resume.php(%d): class@anonymous->__destruct() | ||
#2 {main} | ||
thrown in %sno-switch-dtor-resume.php on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--TEST-- | ||
Cannot start fiber within destructor | ||
--FILE-- | ||
<?php | ||
|
||
return new class () { | ||
public function __destruct() { | ||
$fiber = new Fiber(fn () => null); | ||
$fiber->start(); | ||
} | ||
}; | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Uncaught FiberError: Cannot switch fibers in current execution context in %sno-switch-dtor-start.php:%d | ||
Stack trace: | ||
#0 %sno-switch-dtor-start.php(%d): Fiber->start() | ||
#1 %sno-switch-dtor-start.php(%d): class@anonymous->__destruct() | ||
#2 {main} | ||
thrown in %sno-switch-dtor-start.php on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--TEST-- | ||
Cannot suspend fiber within destructor | ||
--FILE-- | ||
<?php | ||
|
||
$fiber = new Fiber(function () { | ||
$a = new class () { | ||
public function __destruct() { | ||
Fiber::suspend(); | ||
} | ||
}; | ||
}); | ||
|
||
$fiber->start(); | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Uncaught FiberError: Cannot switch fibers in current execution context in %sno-switch-dtor-suspend.php:%d | ||
Stack trace: | ||
#0 %sno-switch-dtor-suspend.php(%d): Fiber::suspend() | ||
#1 [internal function]: class@anonymous->__destruct() | ||
#2 %sno-switch-dtor-suspend.php(%d): Fiber->start() | ||
#3 {main} | ||
thrown in %sno-switch-dtor-suspend.php on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--TEST-- | ||
Cannot resume fiber within destructor | ||
--FILE-- | ||
<?php | ||
|
||
$fiber = new Fiber(function () { | ||
Fiber::suspend(); | ||
}); | ||
$fiber->start(); | ||
|
||
return new class ($fiber) { | ||
private $fiber; | ||
|
||
public function __construct(Fiber $fiber) { | ||
$this->fiber = $fiber; | ||
} | ||
|
||
public function __destruct() { | ||
$this->fiber->throw(new Error()); | ||
} | ||
}; | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Uncaught FiberError: Cannot switch fibers in current execution context in %sno-switch-dtor-throw.php:%d | ||
Stack trace: | ||
#0 %sno-switch-dtor-throw.php(%d): Fiber->throw(Object(Error)) | ||
#1 %sno-switch-dtor-throw.php(%d): class@anonymous->__destruct() | ||
#2 {main} | ||
thrown in %sno-switch-dtor-throw.php on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--TEST-- | ||
Cannot start a new fiber in a finally block in a force-closed fiber | ||
--FILE-- | ||
<?php | ||
|
||
$fiber = new Fiber(function() { | ||
try { | ||
Fiber::suspend(); | ||
} finally { | ||
echo "finally\n"; | ||
|
||
$fiber = new Fiber(function() { | ||
echo "not executed\n"; | ||
}); | ||
|
||
$fiber->start(); | ||
} | ||
}); | ||
|
||
$fiber->start(); | ||
|
||
?> | ||
--EXPECTF-- | ||
finally | ||
|
||
Fatal error: Uncaught FiberError: Cannot switch fibers in current execution context in %sno-switch-force-close-finally.php:%d | ||
Stack trace: | ||
#0 %sno-switch-force-close-finally.php(%d): Fiber->start() | ||
#1 [internal function]: {closure}() | ||
#2 {main} | ||
thrown in %sno-switch-force-close-finally.php on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--TEST-- | ||
Context switches are prevented during GC collect cycles | ||
--FILE-- | ||
<?php | ||
|
||
$fiber = new Fiber(function () { | ||
call_user_func(function () { | ||
$a = new class () {}; | ||
|
||
$b = new class () { | ||
public function __destruct() { | ||
Fiber::suspend(); | ||
} | ||
}; | ||
|
||
$a->next = $b; | ||
$b->next = $a; | ||
}); | ||
|
||
gc_collect_cycles(); | ||
}); | ||
|
||
$fiber->start(); | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Uncaught FiberError: Cannot switch fibers in current execution context in %sno-switch-gc.php:%d | ||
Stack trace: | ||
#0 %sno-switch-gc.php(%d): Fiber::suspend() | ||
#1 [internal function]: class@anonymous->__destruct() | ||
#2 %sno-switch-gc.php(%d): gc_collect_cycles() | ||
#3 [internal function]: {closure}() | ||
#4 %sno-switch-gc.php(%d): Fiber->start() | ||
#5 {main} | ||
thrown in %sno-switch-gc.php on line %d |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.