From 517ef664db90946c731819fd09d26b26cfc12d85 Mon Sep 17 00:00:00 2001 From: walkor Date: Sat, 23 Nov 2024 21:04:08 +0800 Subject: [PATCH] Check __destruct isSafe --- src/Connection/TcpConnection.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Connection/TcpConnection.php b/src/Connection/TcpConnection.php index 38b9f60db..9f33f093f 100644 --- a/src/Connection/TcpConnection.php +++ b/src/Connection/TcpConnection.php @@ -244,6 +244,13 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable */ public ?Request $request = null; + /** + * Is safe. + * + * @var bool + */ + protected bool $isSafe = true; + /** * Default send buffer size. * @@ -1102,6 +1109,16 @@ public function jsonSerialize(): array ]; } + /** + * __wakeup. + * + * @return void + */ + public function __wakeup() + { + $this->isSafe = false; + } + /** * Destruct. * @@ -1110,6 +1127,9 @@ public function jsonSerialize(): array public function __destruct() { static $mod; + if (!$this->isSafe) { + return; + } self::$statistics['connection_count']--; if (Worker::getGracefulStop()) { $mod ??= ceil((self::$statistics['connection_count'] + 1) / 3);