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

php7.2.5 Swoole\Coroutine\Redis 连接阻塞,连接失败 #1599

Closed
GargantuaX opened this issue May 7, 2018 · 6 comments
Closed

php7.2.5 Swoole\Coroutine\Redis 连接阻塞,连接失败 #1599

GargantuaX opened this issue May 7, 2018 · 6 comments
Labels

Comments

@GargantuaX
Copy link

GargantuaX commented May 7, 2018

php7.2.5 Swoole\Coroutine\Redis 连接阻塞,连接失败

php:
7.2.5

swoole:

Version 2.1.3
Author tianfeng.han[email: mikan.tenny@gmail.com]
coroutine enabled
epoll enabled
eventfd enabled
timerfd enabled
signalfd enabled
cpu affinity enabled
spinlock enabled
rwlock enabled
async redis client enabled
async http/websocket client enabled
Linux Native AIO enabled
pcre enabled
zlib enabled
mutex_timedlock enabled
pthread_barrier enabled
futex enabled
mysqlnd enabled
debug enabled

redis-server:
3.2

os:
centos6.5

测试代码:

<?php
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->set('key','php redis is work');
$val = $redis->get('key');
echo $val.PHP_EOL;

go(function (){
    $redis = new \Swoole\Coroutine\Redis();
    $redis->connect('127.0.0.1', 6379);
    $redis->set('key','swoole redis work');
    $val = $redis->get('key');
    echo $val.PHP_EOL;
});

输出:
php redis is work

Segmentation fault

@twose
Copy link
Member

twose commented May 7, 2018

没有复现, 建议按照这个贴一下 https://wiki.swoole.com/wiki/page/10.html

@GargantuaX
Copy link
Author

PHP:
PHP 7.2.5 (cli) (built: Apr 28 2018 11:00:26) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

GCC:
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)

os:
Linux Server-31c6d7d0-9cde-4cc7-81b9-a05b7854d7d7.novalocal 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

bt:
(gdb) bt
#0 zim_swoole_redis_coro_close (execute_data=0x7fc9422821a0, return_value=0x7fff34065d70)
at /tmp/pear/install/swoole/swoole_redis_coro.c:1339
#1 0x0000000000851c51 in zend_call_function (fci=0x7fff34065c70, fci_cache=0x7fff34065cb0)
at /root/lib/php-7.2.5/Zend/zend_execute_API.c:833
#2 0x0000000000881073 in zend_call_method (object=0x7fc942282170, obj_ce=0x2f23140, fn_proxy=,
function_name=0x7fc93c0b2380 "close", function_name_len=5, retval_ptr=0x7fff34065d70, param_count=0, arg1=0x0, arg2=0x0)
at /root/lib/php-7.2.5/Zend/zend_interfaces.c:100
#3 0x00007fc93c072dfd in zim_swoole_redis_coro___destruct (execute_data=0x7fc942282150, return_value=)
at /tmp/pear/install/swoole/swoole_redis_coro.c:1384
#4 0x0000000000851c51 in zend_call_function (fci=0x7fff34065e90, fci_cache=0x7fff34065ed0)
at /root/lib/php-7.2.5/Zend/zend_execute_API.c:833
#5 0x0000000000881073 in zend_call_method (object=0x7fff34065f90, obj_ce=0x2f23140, fn_proxy=,
function_name=0xfd892b "__destruct", function_name_len=10, retval_ptr=0x0, param_count=0, arg1=0x0, arg2=0x0)
at /root/lib/php-7.2.5/Zend/zend_interfaces.c:100
#6 0x000000000089aae2 in zend_objects_destroy_object (object=) at /root/lib/php-7.2.5/Zend/zend_objects.c:146
#7 0x000000000089f9d5 in zend_objects_store_del (object=0x7fc94227f000) at /root/lib/php-7.2.5/Zend/zend_objects_API.c:173
#8 0x000000000090db7d in i_free_compiled_variables (execute_data=0x7fc942282060) at /root/lib/php-7.2.5/Zend/zend_execute.c:2103
#9 zend_leave_helper_SPEC (execute_data=0x7fc942282060) at /root/lib/php-7.2.5/Zend/zend_vm_execute.h:516
#10 0x00000000008a81a8 in execute_ex (ex=) at /root/lib/php-7.2.5/Zend/zend_vm_execute.h:59723
#11 0x00007fc93c012987 in sw_coro_resume (sw_current_context=, retval=0x7fc94226b050, coro_retval=)
at /tmp/pear/install/swoole/swoole_coroutine.c:506
#12 0x00007fc93c072c20 in swoole_redis_coro_onTimeout (timer=, tnode=)
at /tmp/pear/install/swoole/swoole_redis_coro.c:4384
#13 0x00007fc93c09b8d9 in swTimer_select (timer=0x7fc93c36e500 ) at /tmp/pear/install/swoole/src/network/Timer.c:214
#14 0x00007fc93c08636f in swReactor_onTimeout_and_Finish (reactor=0x30159d0)
at /tmp/pear/install/swoole/src/reactor/ReactorBase.c:156
#15 0x00007fc93c088381 in swReactorEpoll_wait (reactor=0x30159d0, timeo=)
at /tmp/pear/install/swoole/src/reactor/ReactorEpoll.c:294
#16 0x00007fc93c01703a in php_swoole_event_wait () at /tmp/pear/install/swoole/swoole_event.c:254
#17 0x0000000000851c51 in zend_call_function (fci=0x7fff340662d0, fci_cache=0x7fff34066260)
at /root/lib/php-7.2.5/Zend/zend_execute_API.c:833
---Type to continue, or q to quit---f 12
#18 0x00000000008522c7 in _call_user_function_ex (object=, function_name=, retval_ptr=,
param_count=, params=, no_separation=)
at /root/lib/php-7.2.5/Zend/zend_execute_API.c:654
#19 0x0000000000751a35 in user_shutdown_function_call (zv=) at /root/lib/php-7.2.5/ext/standard/basic_functions.c:5023
#20 0x000000000086eea3 in zend_hash_apply (ht=0x7fc9422021c0, apply_func=0x751a00 <user_shutdown_function_call>)
at /root/lib/php-7.2.5/Zend/zend_hash.c:1506
#21 0x00000000007519f6 in php_call_shutdown_functions () at /root/lib/php-7.2.5/ext/standard/basic_functions.c:5107
#22 0x00000000008001b5 in php_request_shutdown (dummy=) at /root/lib/php-7.2.5/main/main.c:1846
#23 0x000000000090fcf7 in do_cli (argc=2, argv=0x2dee480) at /root/lib/php-7.2.5/sapi/cli/php_cli.c:1178
#24 0x000000000091115b in main (argc=2, argv=0x2dee480) at /root/lib/php-7.2.5/sapi/cli/php_cli.c:1404

十分感谢

@GargantuaX
Copy link
Author

我用GDB跟到异常退出的地方,swoole_redis_coro.c:1308
redisCallback *head = redis->context->replies.head;
*redis->context的运行时信息是:
{
c = {
err = 0,
errstr = '\000' < repeats 127 times > ,
fd = 5,
flags = 6,
obuf = 0x159ddc8 "",
reader = 0x1603d00,
connection_type = REDIS_CONN_TCP,
timeout = 0x15f5424,
tcp = {
host = 0x0,
source_addr = 0x0,
port = 0
},
unix_sock = {
path = 0x0
}
},
err = 0,
errstr = 0x0,
data = 0x0,
ev = {
data = 0x7ffff2875060,
addRead = 0x7fffec64ebe0 < swoole_redis_coro_event_AddRead > ,
delRead = 0x7fffec64eaa0 < swoole_redis_coro_event_DelRead > ,
addWrite = 0x7fffec64eb40 < swoole_redis_coro_event_AddWrite > ,
delWrite = 0x7fffec64ea00 < swoole_redis_coro_event_DelWrite > ,
cleanup = 0x7fffec645b20 < swoole_redis_coro_event_Cleanup >
},
onDisconnect = 0x15f5330,
onConnect = 0x15f5370,
replies = {
head = 0x21,
tail = 0x15f4980
},
sub = {
invalid = {
head = 0x7ffff594aee8 < main_arena + 104 > ,
tail = 0x20
},
channels = 0x50,
patterns = 0x606c4ca3d743037d
}
}

@GargantuaX
Copy link
Author

GargantuaX commented May 8, 2018

我用swoole的异步redis客户端也连不上。
$client = new swoole_redis; $client->connect('127.0.0.1', 6379, function (swoole_redis $client, $result) { if($result){ $client->set('key', 'swoole async redis work', function (swoole_redis $client, $result) { }); $client->get('key', function (swoole_redis $client, $result) { echo $result.PHP_EOL; }); }else { echo "swoole async redis connect fail".PHP_EOL; } });

swoole async redis connect fail

协程异常退出的原因应该是,connect没有建立,然后去关闭connect,调用了无法访问的错误内存地址。

@twose
Copy link
Member

twose commented May 8, 2018

#1585
你用最新的master分支代码试一下

@GargantuaX
Copy link
Author

编译最新swoole要升级GCC,可能会跟项目里面的C代码有冲突,选择绕过此问题,先用PHP的普通Redis客户端,谢谢了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants