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

Fixed bug: onWorkerStop cannot be triggered. #959

Merged
merged 1 commit into from
Oct 5, 2023
Merged

Fixed bug: onWorkerStop cannot be triggered. #959

merged 1 commit into from
Oct 5, 2023

Conversation

twomiao
Copy link
Contributor

@twomiao twomiao commented Oct 4, 2023

  1. 修复worker 进程无法触发信号,导致onWorkerStop() 无法执行。
$signals = [SIGINT, SIGTERM, SIGHUP, SIGTSTP, SIGQUIT, SIGUSR1, SIGUSR2, SIGIOT, SIGIO];
foreach ($signals as $signal) {
    //   pcntl_signal($signal, SIG_IGN, false); 移除信号屏蔽,重新注册会重写master 信号。
    // Rewrite master process signal.
   static::$globalEvent->onSignal($signal, [static::class, 'signalHandler']);
}
  1. 修复swoole exit() 发生异常:
onWorkerStart
^CWorkerman[start.php] stopping ...
onWorkerStop
PHP Fatal error:  Uncaught Swoole\ExitException: swoole exit in /mnt/c/users/twomiao/desktop/workerman/src/Worker.php:1921
Stack trace:
#0 /mnt/c/users/twomiao/desktop/workerman/src/Worker.php(1192): Workerman\Worker::stopAll()
#1 [internal function]: Workerman\Worker::signalHandler()
#2 {main}
  thrown in /mnt/c/users/twomiao/desktop/workerman/src/Worker.php on line 1921
worker[none:2878] exit with status 65280
Workerman[start.php] has been stopped

try { // Ignore Swoole ExitException: Swoole exit. exit($code); } catch(\Exception $e) { }

  1. 复现代码:
<?php

use Workerman\Events\Swoole;
use Workerman\Worker;

require __DIR__ . "/vendor/autoload.php";

Worker::$eventLoopClass = Swoole::class;
Worker::$stopTimeout = 15;
$worker = new Worker("http://0.0.0.0:8888");
$worker->count = 1;
$worker->onMessage = static fn ($connection) => $connection->send("hello world");

$worker->onWorkerStart = static fn (Worker $worker) => print "onWorkerStart\n";
$worker->onWorkerStop = static fn (Worker $worker) => print "onWorkerStop\n";
Worker::runAll();

@walkor walkor merged commit 79351f7 into walkor:master Oct 5, 2023
0 of 18 checks passed
@walkor
Copy link
Owner

walkor commented Oct 5, 2023

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants