diff --git a/src/Swoole/Actions/EnsureRequestsDontExceedMaxExecutionTime.php b/src/Swoole/Actions/EnsureRequestsDontExceedMaxExecutionTime.php index 787ea9fa2..8437ab362 100644 --- a/src/Swoole/Actions/EnsureRequestsDontExceedMaxExecutionTime.php +++ b/src/Swoole/Actions/EnsureRequestsDontExceedMaxExecutionTime.php @@ -23,23 +23,33 @@ public function __construct( */ public function __invoke() { + $rows = []; + foreach ($this->timerTable as $workerId => $row) { if ((time() - $row['time']) > $this->maxExecutionTime) { - $this->timerTable->del($workerId); + $rows[$workerId] = $row; + } + } - if ($this->server instanceof Server && ! $this->server->exists($row['fd'])) { - continue; - } + foreach ($rows as $workerId => $row) { + if ($this->timerTable->get($workerId, 'fd') !== $row['fd']) { + continue; + } + + $this->timerTable->del($workerId); + + if ($this->server instanceof Server && ! $this->server->exists($row['fd'])) { + continue; + } - $this->extension->dispatchProcessSignal($row['worker_pid'], SIGKILL); + $this->extension->dispatchProcessSignal($row['worker_pid'], SIGKILL); - if ($this->server instanceof Server) { - $response = Response::create($this->server, $row['fd']); + if ($this->server instanceof Server) { + $response = Response::create($this->server, $row['fd']); - if ($response) { - $response->status(408); - $response->end(); - } + if ($response) { + $response->status(408); + $response->end(); } } } diff --git a/tests/EnsureRequestsDontExceedMaxExecutionTimeTest.php b/tests/EnsureRequestsDontExceedMaxExecutionTimeTest.php index a63ee51c7..2b525a4fb 100644 --- a/tests/EnsureRequestsDontExceedMaxExecutionTimeTest.php +++ b/tests/EnsureRequestsDontExceedMaxExecutionTimeTest.php @@ -17,6 +17,7 @@ public function test_process_is_killed_if_current_request_exceeds_max_execution_ $table['fake-worker-id'] = [ 'worker_pid' => 111, 'time' => time() - 60, + 'fd' => 1, ]; $action = new EnsureRequestsDontExceedMaxExecutionTime( @@ -39,4 +40,9 @@ public function del($workerId) { $this->deleted[] = $workerId; } + + public function get($workerId, $field = null) + { + return 1; + } }