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

[5.1]Fix bug #5716 #5718

Merged
merged 1 commit into from
Apr 7, 2025
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
7 changes: 6 additions & 1 deletion src/server/manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ int Server::start_manager_process() {
}

auto fn = [this](void) {
SwooleG.process_type = SW_PROCESS_MANAGER;
gs->manager_pid = SwooleG.pid = getpid();

if (task_worker_num > 0) {
Expand All @@ -124,6 +123,12 @@ int Server::start_manager_process() {
}
}

/*
* Must be set after ProcessPool:start(),
* the default ProcessPool will set type of the main process as SW_PROCESS_MASTER,
* while in server mode it should be SW_PROCESS_MANAGER
*/
SwooleG.process_type = SW_PROCESS_MANAGER;
SW_LOOP_N(worker_num) {
Worker *worker = get_worker(i);
if (spawn_event_worker(worker) < 0) {
Expand Down
49 changes: 49 additions & 0 deletions tests/swoole_process/signal_in_manager_2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
--TEST--
swoole_process: signal in manager with task worker
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';
use Swoole\Process;
use Swoole\Server;

const PID_FILE = __DIR__ . '/manager.pid';

$pm = new SwooleTest\ProcessManager;

$pm->parentFunc = function ($pid) use ($pm) {
usleep(100000);
$manager_pid = file_get_contents(PID_FILE);
Process::kill($manager_pid, SIGINT);
$pm->wait();
$pm->kill();
};

$pm->childFunc = function () use ($pm) {
$serv = new Server('127.0.0.1', $pm->getFreePort(), SWOOLE_PROCESS);
$serv->set([
'worker_num' => 1,
'task_worker_num' => 1,
'log_file' => '/dev/null',
]);
$serv->on('ManagerStart', function (Server $serv) use ($pm) {
file_put_contents(PID_FILE, $serv->getManagerPid());
Process::signal(SIGINT, function () use ($pm) {
echo "SIGINT triggered\n";
$pm->wakeup();
});
$pm->wakeup();
});
$serv->on('Task', function ($server, $taskId, $workerId, $data) {
});
$serv->on('Receive', function (Server $serv, $fd, $reactorId, $data) {
});
$serv->start();
};
$pm->childFirst();
$pm->run();
unlink(PID_FILE);
?>
--EXPECT--
SIGINT triggered
Loading