swoole / swoole-cli

SWOOLE-CLI is a php binary distribution composed swoole & php-core & cli & fpm and mostly of common extensions.
193 stars 36 forks source link

swoole-cli-v5.1.4 reload()偶尔出现假死状态 请求没有响应 要手动kill重启 #789

Closed LIngMax closed 1 month ago

LIngMax commented 2 months ago

swoole-cli-v5.1.4 reload()偶尔出现假死状态 请求没有响应 要手动kill重启

https://www.swoole.com/download swoole-cli-v5.1.4-linux-x64.tar.xz

一分钟请求1次 请求20次
偶尔出现假死状态 链接连接不上

回退官网5.1.3正常了

机器是华为云 2h8g

[root@hw-*-api api]# uname -r
5.10.0-182.0.0.95.r1941_123.hce2.x86_64
[root@hw-*-api api]# uname -a
Linux hw-*-api 5.10.0-182.0.0.95.r1941_123.hce2.x86_64 #1 SMP Fri Jun 28 09:41:47 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
[root@hw-/-api api]# cat /etc/os-release
NAME="Huawei Cloud EulerOS"
VERSION="2.0 (x86_64)"
ID="hce"
VERSION_ID="2.0"
PRETTY_NAME="Huawei Cloud EulerOS 2.0 (x86_64)"
ANSI_COLOR="0;31"

$server = new Swoole\WebSocket\Server("0.0.0.0",4455,SWOOLE_PROCESS );#SWOOLE_PROCESS SWOOLE_THREAD
$server->set([
    'reactor_num'           => swoole_cpu_num()*4,#reactor线程数 1-4倍 默认值:CPU 核数
    'worker_num'            => swoole_cpu_num()*4,#CPU核数的1-4倍 默认值:CPU 核数 Swoole 6多线程版本
    'hook_flags'            => SWOOLE_HOOK_ALL,#开启协程钩子
    'enable_coroutine'      => true,#启用协程
    'task_enable_coroutine' => true,#Task启用协程
    'reload_async'          => true,#触发重启 当前无任何协程时进程才会退出
    'open_http_protocol'    => true,#HTTP协议解析
    'http_parse_cookie'     => false,#自动解析COOKIE请求
    'http_parse_post'       => false,#自动解析POST请求
    'http_parse_files'      => false,#自动解析上传文件
    // 'single_thread'         => true,#单线程模式 SWOOLE_PROCESS强制 ZTS必须开启  cli是NTS所以不用开启

]);

$server->on('WorkerStart', function ($server, $worker_id){
    Swoole\Timer::tick(1000, function(){ usleep(500*1000); });
});
$server->on('message',function ($server, $frame){});
$server->on('request', function ($request, $response){

         $cmd = "cd /home/api/;git fetch --all ; git reset --hard origin/main;";
        $rs = shell_exec($cmd);
        global $server;
        if($reload)$server->reload();#重启服务   
        @$response->end("啊哈哈哈哈");

});
$server->on('close',function ($server, $_fd){});
$server->start();
matyhtf commented 2 months ago

5.1.4 和 5.1.3 差异并不大,没有关于 reload 的修改。建议再跟踪排查一下

@NathanFreeman 可以帮忙 review 下

https://github.com/swoole/swoole-src/compare/v5.1.3...v5.1.4

NathanFreeman commented 2 months ago

要strace -p看看假死的时候进程阻塞在哪一步了

LIngMax commented 2 months ago

要strace -p看看假死的时候进程阻塞在哪一步了

第二个进程卡死了 work进程名我改了

image

LIngMax commented 2 months ago

3台服务器
只有这台是5.1.4 卡住
其他5.1.3 git跟新命令正常 重启也正常

LIngMax commented 2 months ago

双核机器 16 work工作进程

LIngMax commented 1 month ago

换了下写法 暂时没报错了

        $cmd .= "cd ".realpath(SERVER_PATH)."/$pv/;git fetch --all ; git reset --hard origin/$main;";
        $rs = shell_exec($cmd);
        Swoole\Timer::after(3000, function() use ($reload,$cmd) {
            $rs = shell_exec($cmd);
            Swoole\Timer::after(200, function() use ($reload,$cmd) {
                global $server;
                if($reload)$server->reload();#重启服务   
            });
        });
LIngMax commented 1 month ago

还是偶现了 不过频率低很多 已退回 5.1.3

换了下写法暂时没报错了

        $cmd .= "cd ".realpath(SERVER_PATH)."/$pv/;git fetch --all ; git reset --hard origin/$main;";
        $rs = shell_exec($cmd);
        Swoole\Timer::after(3000, function() use ($reload,$cmd) {
            $rs = shell_exec($cmd);
            Swoole\Timer::after(200, function() use ($reload,$cmd) {
                global $server;
                if($reload)$server->reload();#重启服务   
            });
        });