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.0.2版本开始,Process::signal收到不信号回调 #5080

Closed
bobyang007 opened this issue Jun 26, 2023 · 10 comments
Closed

从5.0.2版本开始,Process::signal收到不信号回调 #5080

bobyang007 opened this issue Jun 26, 2023 · 10 comments

Comments

@bobyang007
Copy link

Please answer these questions before submitting your issue.

  1. What did you do? If possible, provide a simple script for reproducing the error.
    Process::signal(SIGTERM, function () {
    echo '收到退出信号';
    $this->pool->getProcess()->exit();
    });

  2. What did you expect to see?
    从5.0.2版本开始,该注册收不到信号回调,切回5.0.1,或4版本均正常

  3. What did you see instead?

  4. What version of Swoole are you using (show your php --ri swoole)?

  5. What is your machine environment used (show your uname -a & php -v & gcc -v) ?
    Swoole => enabled
    Author => Swoole Team team@swoole.com
    Version => 5.0.1
    Built => Jun 26 2023 16:56:00
    coroutine => enabled with boost asm context
    epoll => enabled
    eventfd => enabled
    signalfd => enabled
    cpu_affinity => enabled
    spinlock => enabled
    rwlock => enabled
    sockets => enabled
    openssl => OpenSSL 3.0.2 15 Mar 2022
    dtls => enabled
    http2 => enabled
    json => enabled
    curl-native => enabled
    c-ares => 1.18.1
    mutex_timedlock => enabled
    pthread_barrier => enabled
    futex => enabled
    mysqlnd => enabled
    async_redis => enabled
    coroutine_postgresql => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608

@NathanFreeman
Copy link
Member

麻烦提供一下复现代码。

@bobyang007
Copy link
Author

bobyang007 commented Jun 27, 2023

<?php

use Swoole\Process;
use Swoole\Coroutine;

echo 'Main Process kill -15 ' . posix_getpid() . "\n" . 'swoole version:' . swoole_version() . "\n";
$pool = new Process\Pool(5);
$pool->set(['enable_coroutine' => true]);
$pool->on('WorkerStart', function (Process\Pool $pool, $workerId) {
    /**
     * 当前是 Worker 进程
     */
    static $running = true;
    Process::signal(SIGTERM, function () use (&$running) {
        $running = false;
        echo "TERM\n";
    });
    echo "[Worker #{$workerId}] WorkerStart, pid: " . posix_getpid() . "\n";
    while ($running) {
        Coroutine::sleep(1);
        echo 'sleep 1';
    }
    echo "[Worker #{$workerId}] WorkerStart, pid: " . posix_getpid() . " over\n";
});
$pool->on('WorkerStop', function (\Swoole\Process\Pool $pool, $workerId) {
    echo "[Worker #{$workerId}] WorkerStop\n";
});
$pool->start();

image

image

image

image

image

@NathanFreeman
Copy link
Member

我没法复现出来,在master分支,V5.0.1版本上,发送SIGTERM给主进程可以终止程序运行,发送SIGTERM给子进程,子进程可以退出并且被父进程重新拉起。

@bobyang007
Copy link
Author

5.0.2及之后,是可以结束子进程
但是在些版本之前,使用Process::signal注册的信号回调,是会被执行的
5.0.2及之后,这个回调不会被执行,进程是直接被干死了,就实现不了优雅退出服务了

@bobyang007
Copy link
Author

你看我上面发的图,5.0.1及之前的版本,收到15信号后,是会输出TERM,及进程循环退出时打印的输出
5.0.2及之后,是进程直接死了,没有退出信号输出,没有进程结束输出

@bobyang007
Copy link
Author

image
5.0.2版本之后,这里的没有执行

@NathanFreeman
Copy link
Member

微信截图_20230627144848
微信截图_20230627145108

我这里测试了可以执行,你是在linux环境下的测试的吗?

@bobyang007
Copy link
Author

bobyang007 commented Jun 27, 2023

buntu 22.04
核对了下编译参数,开启了
--enable-thread-context
增强
就不能收到信号了

@NathanFreeman
Copy link
Member

复现出来了,我看看是为啥

matyhtf pushed a commit that referenced this issue Jun 29, 2023
* Fix bug #5080

* fix error
@NathanFreeman
Copy link
Member

Fixed by #5081

matyhtf pushed a commit that referenced this issue Jul 4, 2023
* Fix assert failed

* Fix bug #5080

* fix error

* Fix thread error
@matyhtf matyhtf closed this as completed Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants