Skip to content

Commit 5a92cc4

Browse files
committed
fix(signal): prevent Fiber::switch in pcntl_signal callback
1 parent 6408885 commit 5a92cc4

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/Runtime/Trait/StateMachine.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ public function setState(string $state): void
6565
return;
6666
}
6767

68-
if ($state === Coroutine::STATE_DEAD && isset($this->fiber)) {
69-
if (!$this->fiber->isTerminated()) {
70-
throw new CoroutineException('状态不同步');
71-
}
72-
}
68+
// if ($state === Coroutine::STATE_DEAD && isset($this->fiber)) {
69+
// if (!$this->fiber->isTerminated()) {
70+
// throw new CoroutineException('状态不同步');
71+
// }
72+
// }
7373

7474
$this->state = $state;
7575

src/Watch/StreamWatcher.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
namespace Ripple\Watch;
1414

1515
use Closure;
16+
use Ripple\Coroutine;
17+
use Ripple\Runtime\Scheduler;
1618
use Ripple\Runtime\Support\Display;
1719
use Ripple\Runtime\Support\Stdin;
1820
use Ripple\Watch\Interface\WatchAbstract;
@@ -276,7 +278,10 @@ public function watchSignal(int $signal, Closure $callback): int
276278
if (isset($this->signalWatchers[$signal])) {
277279
foreach ($this->signalWatchers[$signal] as $watchId => $callback) {
278280
try {
279-
$callback($watchId, $signal);
281+
// $callback($watchId, $signal);
282+
$coroutine = Coroutine::create($callback);
283+
$coroutine->bind($watchId, $signal);
284+
Scheduler::enqueue($coroutine);
280285
} catch (Throwable $exception) {
281286
Stdin::println(Display::exception($exception));
282287
}

0 commit comments

Comments
 (0)