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

Fix max_execution_time config doesn't work #510

Merged
merged 4 commits into from
Apr 20, 2022
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
1 change: 1 addition & 0 deletions bin/createSwooleTimerTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

$timerTable->column('worker_pid', Table::TYPE_INT);
$timerTable->column('time', Table::TYPE_INT);
$timerTable->column('fd', Table::TYPE_INT);
sy-records marked this conversation as resolved.
Show resolved Hide resolved

$timerTable->create();

Expand Down
1 change: 1 addition & 0 deletions bin/swoole-server
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ $server->on('request', function ($request, $response) use ($server, $workerState
$workerState->timerTable->set($workerState->workerId, [
'worker_pid' => $workerState->workerPid,
'time' => time(),
'fd' => $request->fd,
]);
}

Expand Down
11 changes: 10 additions & 1 deletion src/Swoole/Actions/EnsureRequestsDontExceedMaxExecutionTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
namespace Laravel\Octane\Swoole\Actions;

use Laravel\Octane\Swoole\SwooleExtension;
use Swoole\Http\Response;
use Swoole\Http\Server;

class EnsureRequestsDontExceedMaxExecutionTime
{
public function __construct(
protected SwooleExtension $extension,
protected $timerTable,
protected $maxExecutionTime
protected $maxExecutionTime,
protected ?Server $server = null
) {
}

Expand All @@ -25,6 +28,12 @@ public function __invoke()
$this->timerTable->del($workerId);

$this->extension->dispatchProcessSignal($row['worker_pid'], SIGKILL);

if ($this->server instanceof Server) {
$response = Response::create($this->server, $row['fd']);
$response->status(408);
$response->end();
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Swoole/Handlers/OnServerStart.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public function __invoke($server)
}

if ($this->maxExecutionTime > 0) {
$server->tick(1000, function () {
$server->tick(1000, function () use ($server) {
(new EnsureRequestsDontExceedMaxExecutionTime(
$this->extension, $this->timerTable, $this->maxExecutionTime
$this->extension, $this->timerTable, $this->maxExecutionTime, $server
))();
});
}
Expand Down