Skip to content

Commit

Permalink
Do not perform deletion operations during traversal (#941)
Browse files Browse the repository at this point in the history
* Do not perform deletion operations during traversal (all keys can be taken out for deletion after traversal)

Do not perform deletion operations during traversal (all keys can be taken out for deletion after traversal)

* fix bug

* fix bug

* fix bug

* fix bug

* Update EnsureRequestsDontExceedMaxExecutionTime.php

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
hughcube and taylorotwell authored Aug 9, 2024
1 parent 919a4ae commit d7b8991
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/Swoole/Actions/EnsureRequestsDontExceedMaxExecutionTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/EnsureRequestsDontExceedMaxExecutionTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -39,4 +40,9 @@ public function del($workerId)
{
$this->deleted[] = $workerId;
}

public function get($workerId, $field = null)
{
return 1;
}
}

0 comments on commit d7b8991

Please sign in to comment.