Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not perform deletion operations during traversal #941

Merged
merged 6 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}