Skip to content

Commit

Permalink
fix(swoole): Multiple Workers in SWOOLE_BASE mode (#2778)
Browse files Browse the repository at this point in the history
* fix: Change fork handling condition

* fix: Change fork handling condition

* fix: Send a SIGTERM instead of SIGKILL

* Revise integration

* On handle_fork on worker start

* Remove debug logs

* fix: Fat finger

* Remove debug logs
  • Loading branch information
PROFeNoM authored Jul 30, 2024
1 parent 2ec6aab commit 1f388b3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 29 deletions.
28 changes: 1 addition & 27 deletions src/DDTrace/Integrations/Swoole/SwooleIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,8 @@ function (HookData $hook) use ($integration, $server, $scheme) {

public function instrumentWorkerStart(callable $callback, SwooleIntegration $integration, Server $server)
{
if ($server->mode === SWOOLE_BASE) {
return;
}

\DDTrace\install_hook(
$callback,
function (HookData $hook) use ($integration, $server) {
handle_fork();
}
);
}

public function instrumentWorkerStop(callable $callback, SwooleIntegration $integration, Server $server)
{
if ($server->mode === SWOOLE_BASE) {
return;
}

\DDTrace\install_hook(
$callback,
null,
function (HookData $hook) use ($integration, $server) {
handle_fork();
}
Expand All @@ -151,9 +132,7 @@ public function init(): int
'__construct',
null,
function ($server) use ($integration) {
foreach (['workerstart', 'workerstop', 'workerexit', 'workererror'] as $serverEvent) {
$server->on($serverEvent, function () { });
}
$server->on('workerstart', function () { });
}
);

Expand All @@ -176,11 +155,6 @@ function ($server, $scope, $args, $retval) use ($integration) {
case 'workerstart':
$integration->instrumentWorkerStart($callback, $integration, $server);
break;
case 'workerstop':
case 'workerexit':
case 'workererror':
$integration->instrumentWorkerStop($callback, $integration, $server);
break;
}

}
Expand Down
4 changes: 3 additions & 1 deletion tests/Frameworks/Swoole/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
require __DIR__ . '/../../vendor/autoload.php';

$http = new Swoole\Http\Server("0.0.0.0", 9999);

$http->set([
'worker_num' => 2
]);
$http->on('request', function ($request, $response) {
$requestUri = $request->server['request_uri'];

Expand Down
2 changes: 1 addition & 1 deletion tests/Sapi/SwooleServer/SwooleServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function start()
public function stop()
{
error_log("[swoole-server] Stopping...");
$this->process->stop(0);
$this->process->stop(0, SIGTERM);
}

public function isFastCgi()
Expand Down

0 comments on commit 1f388b3

Please sign in to comment.