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

swoole-1.8.5-alpha, websocket使用task有问题 #653

Closed
samblabla opened this issue May 4, 2016 · 10 comments
Closed

swoole-1.8.5-alpha, websocket使用task有问题 #653

samblabla opened this issue May 4, 2016 · 10 comments

Comments

@samblabla
Copy link

samblabla commented May 4, 2016

不使用task正常,使用了task 后 websocket的message不能正常处理.
test1.php

 <?php
$serv = new swoole_websocket_server("0.0.0.0", 9501);

$serv->set(array(
    'worker_num'=>1,
    'task_worker_num' => 1,
));

$serv->on('open', function($server, $req) {
    echo "connection open: ".$req->fd;
});

$serv->on('message', function($server, $frame) {
    echo "message: ".$frame->data;
});

$serv->on('close', function($server, $fd) {
    echo "connection close: ".$fd;
});


$serv->on('task', function($server, $task_id, $from_id,$data){
    echo 'task';
});

$serv->on('finish',function($server, $task_id,$data){
    echo 'finish';
});



$serv->start();

websocket连接时报错:
PHP Warning: Invalid callback , no array or string given in /Swoole/swoole_chat/test1.php on line 32

Warning: Invalid callback , no array or string given in /Swoole/swoole_chat/test1.php on line 32
PHP Warning: swoole_http_server::start(): onOpen handler error in /Swoole/swoole_chat/test1.php on line 32

Warning: swoole_http_server::start(): onOpen handler error in /Swoole/swoole_chat/test1.php on line 32
[2016-05-04 11:12:24 $25283.0] WARNING swManager_check_exit_status: worker#0 abnormal exit, status=0, signal=11

test2.php

<?php
class Message
{
    function run(){
        $serv = new \swoole_websocket_server('0.0.0.0', 9501);
        $serv->set( array(
            'worker_num'=>1,
            'task_worker_num' => 1,
        ));

        $serv->on('open', array($this,'wsConnect'));

        $serv->on('message', array($this,'wsMessage'));

        $serv->on('task', array($this,'wsTask'));
        $serv->on('finish',function($server, $task_id,$data){
            // echo 'send finish:'.$data;
        });

        $serv->on('close', array($this,'wsClose'));



        $serv->start();
    }


    function wsConnect(\swoole_websocket_server $serv, $request) {

        echo "server: handshake success with fd{$request->fd}\n";
    }

    function wsMessage(\swoole_websocket_server $serv, $frame) {
        echo 'wsMessage';

    }




    public function wsTask($server, $task_id, $from_id,$data) {

        echo 'wsTask';
    }

    function wsClose($serv, $fd) {
        echo "client {$fd} closed\n";

    }


}
$Msg = new Message();
$Msg->run();

websocket连接时报错:
server: handshake success with fd1
[2016-05-04 11:17:39 $25413.0] WARNING swManager_check_exit_status: worker#0 abnormal exit, status=0, signal=11

@matyhtf
Copy link
Member

matyhtf commented May 4, 2016

swoole-1.8.5-alpha 是github release页面中下载的吗?还是直接git clone的版本,如果是git,请更新一下代码 git pull

@samblabla
Copy link
Author

samblabla commented May 4, 2016

使用 git pull更新到最新代码也是一样有这些问题.

使用 commit 0227513
运行一段时间会挂.(环境 php5.6 websocket 多协议 )
#0 0x00007f75e02d5cc9 in __GI_raise (sig=sig@entry=6)
at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1 0x00007f75e02d90d8 in __GI_abort () at abort.c:89
#2 0x00007f75e0312394 in __libc_message (do_abort=do_abort@entry=1,
fmt=fmt@entry=0x7f75e0420b28 "*** Error in `%s': %s: 0x%s ***\n")
at ../sysdeps/posix/libc_fatal.c:175
#3 0x00007f75e031e66e in malloc_printerr (ptr=,
str=0x7f75e0420ca0 "free(): invalid next size (normal)", action=1) at malloc.c:4996
#4 _int_free (av=, p=, have_lock=0) at malloc.c:3840
#5 0x00007f75df95ccb2 in swString_free (str=0x7f7579b58fc0)
at /var/local/swoole-src/src/core/string.c:83
#6 0x00007f75df96ddc5 in swReactorThread_close (reactor=0x7f75df0964e8, fd=8752)
at /var/local/swoole-src/src/network/ReactorThread.c:310
#7 0x00007f75df96ef97 in swReactorThread_send (_send=_send@entry=0x7f759d6e8d30)
at /var/local/swoole-src/src/network/ReactorThread.c:579
#8 0x00007f75df96f2e6 in swReactorThread_onPipeReceive (reactor=,
ev=0x7f759d6eade0) at /var/local/swoole-src/src/network/ReactorThread.c:423
#9 0x00007f75df965650 in swReactorEpoll_wait (reactor=0x7f75df0964e8,
timeo=) at /var/local/swoole-src/src/reactor/ReactorEpoll.c:258
#10 0x00007f75df96f750 in swReactorThread_loop_stream (param=)
at /var/local/swoole-src/src/network/ReactorThread.c:1155
#11 0x00007f75df717182 in start_thread (arg=0x7f759d6eb700) at pthread_create.c:312
#12 0x00007f75e039947d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111

@millken
Copy link

millken commented May 4, 2016

1.8.4也有问题,官方的demo都跑不了。
后面自己去掉onOpen变通实现了。

@matyhtf
Copy link
Member

matyhtf commented May 4, 2016

本地无法重现此问题,你git pull 后执行make clean了吗?

@samblabla
Copy link
Author

抱歉,本地用的是PHP7,在php5.6下 test1.php 和 test2.php 都是正常的.
我现在使用1.8.5-beta版测试一段时间看看 websocket 多协议, 会不会挂掉.

@samblabla
Copy link
Author

使用1.8.5-beta php5.6 websocket多协议还是会挂掉

*** Error in `php': free(): invalid size: 0x00007efcc07108c0 ***
Aborted (core dumped)

core:

#0 0x00007efd184e6cc9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1 0x00007efd184ea0d8 in __GI_abort () at abort.c:89
#2 0x00007efd18523394 in __libc_message (do_abort=do_abort@entry=1, fmt=fmt@entry=0x7efd18631b28 "*** Error in `%s': %s: 0x%s ***\n")
at ../sysdeps/posix/libc_fatal.c:175
#3 0x00007efd1852f66e in malloc_printerr (ptr=, str=0x7efd1862dc31 "free(): invalid size", action=1) at malloc.c:4996
#4 _int_free (av=, p=, have_lock=0) at malloc.c:3840
#5 0x00007efd17b6de72 in swString_free (str=0x7efcc06c0720) at /var/local/swoole-src/src/core/string.c:83
#6 0x00007efd17b7ef0d in swReactorThread_close (reactor=0x7efd172a7d68, fd=1126) at /var/local/swoole-src/src/network/ReactorThread.c:313
#7 0x00007efd17b80197 in swReactorThread_send (_send=_send@entry=0x7efcd48f7d30) at /var/local/swoole-src/src/network/ReactorThread.c:585
#8 0x00007efd17b804e6 in swReactorThread_onPipeReceive (reactor=, ev=0x7efcd48f9de0)
at /var/local/swoole-src/src/network/ReactorThread.c:429
#9 0x00007efd17b767a0 in swReactorEpoll_wait (reactor=0x7efd172a7d68, timeo=)
at /var/local/swoole-src/src/reactor/ReactorEpoll.c:258
#10 0x00007efd17b80950 in swReactorThread_loop_stream (param=) at /var/local/swoole-src/src/network/ReactorThread.c:1161
#11 0x00007efd17928182 in start_thread (arg=0x7efcd48fa700) at pthread_create.c:312
#12 0x00007efd185aa47d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111

@matyhtf
Copy link
Member

matyhtf commented May 6, 2016

是否可以稳定重现,如果可以请发给一下demo程序。

@samblabla
Copy link
Author

samblabla commented May 6, 2016

本地跑比较正常.无法稳定重现.

生产环境随着用户量的增多,从每天挂两三次到现在几十次.
单台服务器连接量少的时候 2k-3k,多的时候有10k的连接量.服务器的负载也比较正常
多台服务器推送的内容都相同,从多台服务器swoole重启日志上来看,也没有什么规律可循

有的时候也会无限报错
ERROR swProtocol_recv_check_length(:137): recv from socket#1872 failed. Error: Bad address[14].

@matyhtf
Copy link
Member

matyhtf commented May 6, 2016

暂时无法确定是哪里出错,稍后会尝试进行修复。请加我的QQ以方便沟通。 12811247

@matyhtf
Copy link
Member

matyhtf commented May 6, 2016

1.8.5-rc1 已修复websocket crash问题

@matyhtf matyhtf closed this as completed May 6, 2016
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

No branches or pull requests

3 participants