Просмотр исходного кода

fix: all coroutines must be canceled before Event::exit

chaz6chez 1 год назад
Родитель
Сommit
eff0fa1c8b
1 измененных файлов с 5 добавлено и 0 удалено
  1. 5 0
      src/Events/Swoole.php

+ 5 - 0
src/Events/Swoole.php

@@ -15,6 +15,7 @@ declare(strict_types=1);
 
 namespace Workerman\Events;
 
+use Swoole\Coroutine;
 use Swoole\Event;
 use Swoole\Process;
 use Swoole\Timer;
@@ -211,6 +212,10 @@ final class Swoole implements EventInterface
      */
     public function stop(): void
     {
+        // cancel all coroutines before Event::exit
+        foreach (Coroutine::listCoroutines() as $coroutine) {
+            Coroutine::cancel($coroutine);
+        }
         Event::exit();
         posix_kill(posix_getpid(), SIGINT);
     }