Parcourir la source

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

chaz6chez il y a 1 an
Parent
commit
eff0fa1c8b
1 fichiers modifiés avec 5 ajouts et 0 suppressions
  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);
     }