Skip to content

Commit

Permalink
Fix bug #5558 (#5571)
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFreeman authored Nov 20, 2024
1 parent 84d9b51 commit 0f8f2be
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ext-src/swoole_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3809,14 +3809,15 @@ static PHP_METHOD(swoole_server, stop) {
}

zend_bool wait_reactor = 0;
zend_long worker_id = SwooleG.process_id;
zend_long worker_id = -1;

ZEND_PARSE_PARAMETERS_START(0, 2)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(worker_id)
Z_PARAM_BOOL(wait_reactor)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

worker_id = worker_id < 0 ? SwooleG.process_id : worker_id;
if (worker_id == SwooleG.process_id && wait_reactor == 0) {
if (SwooleTG.reactor != nullptr) {
SwooleTG.reactor->defer(
Expand Down
46 changes: 46 additions & 0 deletions tests/swoole_server/named_parameters.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
--TEST--
swoole_server: new twice
--SKIPIF--
<?php
require __DIR__ . '/../include/skipif.inc';
?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';
use Swoole\Constant;
use Swoole\Http\Server;
use Swoole\Event;
$pm = new SwooleTest\ProcessManager;
$atomic = new Swoole\Atomic();
$pm->parentFunc = function ($pid) use ($pm, $atomic) {
posix_kill($atomic->get(), SIGINT);
$pm->wait();
$pm->kill();
};
$pm->childFunc = function () use ($pm, $atomic) {
$http = new Server('0.0.0.0', 9501, SWOOLE_PROCESS);
$http->set([
Constant::OPTION_WORKER_NUM => 1
]);
$http->on('WorkerStart', function () use ($pm, $http, $atomic) {
if ($atomic->get() == 0) {
$atomic->set(posix_getpid());
Event::defer(function () use ($pm) {
$pm->wakeup();
});
Swoole\Coroutine\System::waitSignal(SIGINT);
var_dump($http->stop(waitEvent: true), $http->getLastError());
} else {
$pm->wakeup();
}
});
$http->on('request', function () {
});
$http->start();
};
$pm->childFirst();
$pm->run();
?>
--EXPECT--
bool(true)
int(0)

0 comments on commit 0f8f2be

Please sign in to comment.