326 Star 1.6K Fork 345

GVPswoole / swoole-src

 / 详情

Server 的 Worker 进程默认开启协程的BUG

Done
Opened this issue  
2019-04-27 16:30

先上示例代码, 如下:

$http = new Swoole\Http\Server("0.0.0.0", 8888);
$http->set([
    'worker_num' => 1,
    'max_request' => 1,
]);
$http->on('start', function(){
    swoole_set_process_name('LOCAL::master');
});
$http->on('managerstart', function(){
    swoole_set_process_name('LOCAL::manager');
});
$http->on('request', function ($request, $response)use($http) {
    printf("REQUEST: pid[%d] cid[%d] cnum[%d] uri[%s]\n", getmypid(), Co::getcid(), sizeof(Co::list()), $request->server['request_uri']);
    
    // 使用协程的等待会被挂起.
    Co::sleep(2);

    // 同样的情况, 使用官网给的协程的连接数据的方法, 也会被挂起.
    // $swoole_mysql = new Swoole\Coroutine\MySQL();
    // $swoole_mysql->connect([
    //     'host' => '127.0.0.1',
    //     'port' => 3306,
    //     'user' => 'user',
    //     'password' => 'pass',
    //     'database' => 'test',
    // ]);
    
    $response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>");
});
$http->on('workerstart', function($serv, $worker_id){
    swoole_set_process_name('LOCAL::worker');
    printf("WORKERSTART: pid[%d] cid[%d] cnum[%d]\n", getmypid(), Co::getcid(), sizeof(Co::list()));
});
$http->on('workerstop', function(swoole_server $server, int $worker_id){
    printf("WORKERSTOP: pid[%d] cid[%d] cnum[%d]\n", getmypid(), Co::getcid(), sizeof(Co::list()));
});
$http->start();

// PHP 7.2.0
// Swoole 4.3.2

当时请求数达到max_request的最后一次时请求就会被卡住, 因为协程可能已经被销毁.
我测试时不只是Co::sleep会卡住, 就是连接数据库也会被卡住.

Comments (0)

拓荒者 created任务
拓荒者 changed description
拓荒者 changed description
Rango changed issue state from 待办的 to 已完成
Expand operation logs

Sign in to comment

Status
Assignees
Milestones
Pull Requests
Successfully merging a pull request will close this issue.
Branches
Planed to start   -   Planed to end
-
Top level
Priority
参与者(1)
C
1
https://gitee.com/swoole/swoole.git
git@gitee.com:swoole/swoole.git
swoole
swoole
swoole-src

Search

344bd9b3 5694891 D2dac590 5694891