Swoole-src: ERROR swFactoryProcess_finish (ERROR 1004): send 66 byte failed, because session#134 is closed.

Created on 1 May 2016  ·  23Comments  ·  Source: swoole/swoole-src

环境 php7.0.3+ swoole1.8.4

Most helpful comment

您好!请问什么情况下会导致这个链接关闭呀?我是在用 wrk 做压力测试的时候遇到这种情况的。

All 23 comments

我没有明白 为什么 finish这个错误出现后 swoole 会挂掉,但是我安装了 jemalloc 后就不挂掉了但是这个错误还在。@Rango 是我们代码写的问题 ?swoole 兼容php7的问题?还是php7的问题?困惑!。
`
/**

  • worker: send to client
    */
    static int swFactoryProcess_finish(swFactory *factory, swSendData *resp)
    {
    int ret, sendn;
    swServer *serv = factory->ptr;
    int fd = resp->info.fd;

swConnection *conn = swServer_connection_verify(serv, fd);
if (!conn)
{
swoole_error_log(SW_LOG_NOTICE, SW_ERROR_SESSION_NOT_EXIST, "session#%d does not exist.", fd);
return SW_ERR;
}
else if ((conn->closed || conn->removed) && resp->info.type != SW_EVENT_CLOSE)
{
int _len = resp->length > 0 ? resp->length : resp->info.len;
swoole_error_log(SW_LOG_NOTICE, SW_ERROR_SESSION_CLOSED, "send %d byte failed, because session#%d is closed.", _len, fd);
return SW_ERR;
}
else if (conn->overflow)
{
swoole_error_log(SW_LOG_WARNING, SW_ERROR_OUTPUT_BUFFER_OVERFLOW, "send failed, session#%d output buffer has been overflowed.", fd);
return SW_ERR;
}

swEventData ev_data;
ev_data.info.fd = fd;
ev_data.info.type = resp->info.type;
swWorker *worker = swServer_get_worker(serv, SwooleWG.id);

/**

  • Big response, use shared memory
    */
    if (resp->length > 0)
    {
    if (worker->send_shm == NULL)
    {
    swWarn("send failed, data is too big.");
    return SW_ERR;
    }
swPackage_response response;

worker->lock.lock(&worker->lock);

response.length = resp->length;
response.worker_id = SwooleWG.id;

//swWarn("BigPackage, length=%d|worker_id=%d", response.length, response.worker_id);

ev_data.info.from_fd = SW_RESPONSE_BIG;
ev_data.info.len = sizeof(response);

memcpy(ev_data.data, &response, sizeof(response));
memcpy(worker->send_shm, resp->data, resp->length);
}
else
{
//copy data
memcpy(ev_data.data, resp->data, resp->info.len);

ev_data.info.len = resp->info.len;
ev_data.info.from_fd = SW_RESPONSE_SMALL;
}

ev_data.info.from_id = conn->from_id;

sendn = ev_data.info.len + sizeof(resp->info);
swTrace("[Worker] send: sendn=%d|type=%d|content=%s", sendn, resp->info.type, resp->data);
ret = swWorker_send2reactor(&ev_data, sendn, fd);
if (ret < 0)
{
swWarn("sendto to reactor failed. Error: %s [%d]", strerror(errno), errno);
}
return ret;
}

static int swFactoryProcess_end(swFactory *factory, int fd)
{
swServer *serv = factory->ptr;
swSendData _send;
swDataHead info;

bzero(&_send, sizeof(_send));
_send.info.fd = fd;
_send.info.len = 0;
_send.info.type = SW_EVENT_CLOSE;

swConnection *conn = swWorker_get_connection(serv, fd);
if (conn == NULL || conn->active == 0)
{
    //swWarn("can not close. Connection[%d] not found.", _send.info.fd);
    return SW_ERR;
}
else if (conn->close_force)
{
    goto do_close;
}
else if (conn->closing)
{
    swoole_error_log(SW_LOG_NOTICE, SW_ERROR_SESSION_CLOSING, "The connection[%d] is closing.", fd);
    return SW_ERR;
}
else if (conn->closed)
{
    return SW_ERR;
}
else
{
    do_close:
    conn->closing = 1;
    if (serv->onClose != NULL)
    {
        info.fd = fd;
        info.from_id =  conn->from_id;
        info.from_fd =  conn->from_fd;
        serv->onClose(serv, &info);
    }
    conn->closing = 0;
    conn->closed = 1;
    return factory->finish(factory, &_send);
}

}
`

是指发生了core dump吗?可以用gdb跟踪一下

目前PHP7下还存在一些问题,请使用PHP5.6测试一下。

这个是出现这个swoole进程还在,但是就是不能正常工作的时候出gdb -》bt出来的堆栈调用 @matyhtf 这个应该怎么排查错误呢 ?

(gdb) bt

0 0x00007f7ee354cb7d in poll () from /lib64/libc.so.6

1 0x00007f7ed9604ad2 in swReactorPoll_wait (reactor=0x7f7ed8c02368, timeo=)

at /root/softsource/swoole-src-swoole-1.8.4-stable/src/reactor/ReactorPoll.c:219

2 0x00007f7ed9608e93 in swServer_start_proxy (serv=0x7f7ed88b0000)

at /root/softsource/swoole-src-swoole-1.8.4-stable/src/network/Server.c:360

3 swServer_start (serv=serv@entry=0x7f7ed88b0000)

at /root/softsource/swoole-src-swoole-1.8.4-stable/src/network/Server.c:633

4 0x00007f7ed95f15b7 in zim_swoole_http_server_start (execute_data=0x7f7ee0213160, return_value=0x7f7ee0213140)

at /root/softsource/swoole-src-swoole-1.8.4-stable/swoole_http_server.c:1674

5 0x0000000000870f5b in ZEND_DO_FCALL_SPEC_HANDLER () at /root/softsource/php-7.0.3/Zend/zend_vm_execute.h:842

6 0x0000000000833b9b in execute_ex (ex=) at /root/softsource/php-7.0.3/Zend/zend_vm_execute.h:414

7 0x000000000087ca57 in zend_execute (op_array=0x7f7ee0285000, op_array@entry=0x7f7ed596ea40,

return_value=return_value@entry=0x7f7ee02130a0) at /root/softsource/php-7.0.3/Zend/zend_vm_execute.h:458

8 0x00000000007f8504 in zend_execute_scripts (type=type@entry=8, retval=0x7f7ee02130a0, retval@entry=0x0,

file_count=file_count@entry=3) at /root/softsource/php-7.0.3/Zend/zend.c:1427

9 0x000000000079d1f0 in php_execute_script (primary_file=primary_file@entry=0x7fff32c761c0)

at /root/softsource/php-7.0.3/main/main.c:2484

10 0x000000000087e5da in do_cli (argc=2, argv=0x249c070) at /root/softsource/php-7.0.3/sapi/cli/php_cli.c:974

11 0x000000000044063f in main (argc=2, argv=0x249c070) at /root/softsource/php-7.0.3/sapi/cli/php_cli.c:1345

是WebSocket服务器吗?如果是swoole_websocket_server 请更新Swoole至 1.8.5 版本。

嗯,赞赞赞赞赞赞👍

@matyhtf 更1.8.5 版本提示这个错误 ❌
PHP Warning: swoole_http_server::start(): onOpen handler error in /App/banyar/swoole/banyarWebServer.php on line 42

不明白为什么开 swoole_websocket_server 提示swoole_http_server的错误
代码如下 最后一行为42行
`
$serv = new swoole_websocket_server(SERVER_IP, 9443);
$time=date("y-m");
$com = date("d");
$dir="./data/log/".$time .'/'. $com;
if(!file_exists($dir)){
//如果不创建,递归创建
mkdir($dir,0777,true);
}
$serv->set(array(
'worker_num' => 8,
'daemonize' => true,
'max_request' => 1000,
'max_conn' => 650000,
'dispatch_mode' => 2,
'debug_mode'=> 1,
'task_worker_num'=>100,
'log_file' => $dir."/swoole.log",
'buffer_output_size' => 32 * 1024 *1024,
//'heartbeat_check_interval'=>30,
//'heartbeat_idle_time' => 60, //默认是heartbeat_check_interval的2倍,超过此设置客户端没有回应则强制断开链接
));
$serv->on('Start', array($this, 'onStart'));
$serv->on('open', array($this, 'onOpen'));
$serv->on('message', array($this, 'onMessage'));
$serv->on('Task',array($this,'onTask'));
$serv->on('Finish',array($this,'onFinish'));
$serv->on('close', array($this, 'onClose'));

42 行 $serv->start();

`

swoole源码里面确实调这个了,但是不明白他们之间的逻辑关系

贴代码尽量用md标记,看着太困难了

$serv = new swoole_websocket_server(SERVER_IP, 9443);
$time=date("y-m");
$com = date("d");
$dir="./data/log/".$time .'/'. $com;
if(!file_exists($dir)){
        //如果不创建,递归创建
        mkdir($dir,0777,true);
}
$serv->set(array(
        'worker_num' => 8,
        'daemonize' => true,
        'max_request' => 1000,
        'max_conn' => 650000,
        'dispatch_mode' => 2,
        'debug_mode'=> 1,
        'task_worker_num'=>100,
        'log_file' => $dir."/swoole.log",
        'buffer_output_size' => 32 * 1024 *1024,
        //'heartbeat_check_interval'=>30,
        //'heartbeat_idle_time' => 60, //默认是heartbeat_check_interval的2倍,超过此设置客户端没有回应则强制断开链接
        ));
$serv->on('Start', array($this, 'onStart'));
$serv->on('open', array($this, 'onOpen'));
$serv->on('message', array($this, 'onMessage'));
$serv->on('Task',array($this,'onTask'));
$serv->on('Finish',array($this,'onFinish'));
$serv->on('close', array($this, 'onClose'));
$serv->start();

PHP7特有的问题,在最新的 1.8.5-rc2 已经修复了。如果是主进程crash,进程已经不存在了,这种情况请设置core dump相关内核参数,使用gdb工具进行问题跟踪。如果是进程还在,但是无法工作,可以使用gdb , strace 工具跟踪。

swoole_http_server + Phalcon 不知道为什么报这个错,NOTICE swFactoryProcess_finish (ERROR 1004): send 2336 byte failed, because connection[fd=13] is closed

这表示连接已关闭。

您好!请问什么情况下会导致这个链接关闭呀?我是在用 wrk 做压力测试的时候遇到这种情况的。

我用的swoole这个版本 swoole-src-2.0.9,PHP是这个版本 PHP 7.0.13

我也是在wrk压测时候 出现这个错误了 php7.2.9 swoole 4.1.2

@mitoop
是不是使用了指定时间长度的测试, 对端切断了连接就会出现这个, 现在是notice级别错误

@twose 是的 确实是指定时间了 而且错误提示是notice Thanks

我用Swoole-4.2.8也是,在本机ab测试 -n 1000 -c 100没有问题,但是在docker里就会有这个错误

已更新文档: https://wiki.swoole.com/wiki/page/982.html

Page#982 Not Found. ###

image

这表示连接已关闭。

你好,这种情况会触发回调函数么?close回调好像不响应这种情况

Was this page helpful?
0 / 5 - 0 ratings