walkor 11 месяцев назад
Родитель
Сommit
517ef664db
1 измененных файлов с 20 добавлено и 0 удалено
  1. 20 0
      src/Connection/TcpConnection.php

+ 20 - 0
src/Connection/TcpConnection.php

@@ -245,6 +245,13 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
     public ?Request $request = null;
 
     /**
+     * Is safe.
+     *
+     * @var bool
+     */
+    protected bool $isSafe = true;
+
+    /**
      * Default send buffer size.
      *
      * @var int
@@ -1103,6 +1110,16 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
     }
 
     /**
+     * __wakeup.
+     *
+     * @return void
+     */
+    public function __wakeup()
+    {
+        $this->isSafe = false;
+    }
+
+    /**
      * Destruct.
      *
      * @return void
@@ -1110,6 +1127,9 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
     public function __destruct()
     {
         static $mod;
+        if (!$this->isSafe) {
+            return;
+        }
         self::$statistics['connection_count']--;
         if (Worker::getGracefulStop()) {
             $mod ??= ceil((self::$statistics['connection_count'] + 1) / 3);