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\Coroutine\Redis 处理redis返回的错误问题 #2149

Closed
aimpsmile opened this issue Nov 25, 2018 · 2 comments
Closed

\Swoole\Coroutine\Redis 处理redis返回的错误问题 #2149

aimpsmile opened this issue Nov 25, 2018 · 2 comments

Comments

@aimpsmile
Copy link

  1. What did you do? If possible, provide a simple script for reproducing the error.

请详细描述问题的产生过程,贴出相关的代码,最好能提供一份可稳定重现的简单脚本代码。
redis服务端版本 redis-cli 4.9.105
没有设置密码
没有绑定IP
没有关闭保护操作
操作代码如下:

       cli_set_process_title('uqudu-coroutine-master');
	\swoole\coroutine::set(self::COROUTINE_CONF);

	$http = new \swoole\http\server('127.0.0.1',9501,SWOOLE_PROCESS,SWOOLE_SOCK_TCP);
	$http->on('request',function (\swoole\http\request $request,\swoole\http\response $response){
		$a1 = go(function () {
			file_put_contents('/tmp/a.txt',22222);
		});
		$redis = new \Swoole\Coroutine\Redis();
		$redis->connect('redis.service', 6401);
		
		$authRes = true;
		$data = '';
		if ($redis->connected && $authRes) {
			$val = $redis->set('key',2222);
			$data = $redis->get('key');
		}

		$response->end($data);
		$this->log('msg get '.$data.'[is_connect]'.$redis->connected . '[auth]'.(string)$authRes);

});

phpredis扩展,操作结果如下:
	DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

应该是没有处理好redis的错误,造成崩溃。
  1. What did you expect to see?

期望的结果是什么?
简单的redis操作,可以正常的写入到Redis中

  1. What did you see instead?

实际运行的结果是什么?
swoole被卡住很久,然后发生coredump

coredump 如下:
#0 0x00007f250c9d9518 in sdslen (s=0x2064657473657571 <Address 0x2064657473657571 out of bounds>)
at /home/package/swoole-src-4.2.8/thirdparty/hiredis/sds.h:87
#1 0x00007f250c9da492 in sdscatlen (s=0x2064657473657571 <Address 0x2064657473657571 out of bounds>, t=0x1ad1c23, len=22)
at /home/package/swoole-src-4.2.8/thirdparty/hiredis/sds.c:380
#2 0x00007f250c9d652d in __redisAppendCommand (c=0x1acd4e0, cmd=0x1ad1c23 "*2\r\n$3\r\nGET\r\n$3\r\nkey\r\n", len=22)
at /home/package/swoole-src-4.2.8/thirdparty/hiredis/hiredis.c:900
#3 0x00007f250c9d6788 in redisAppendCommandArgv (c=0x1acd4e0, argc=2, argv=0x7f250a5f0ea0, argvlen=0x7f250a5f0e90)
at /home/package/swoole-src-4.2.8/thirdparty/hiredis/hiredis.c:961
#4 0x00007f250c9d6922 in redisCommandArgv (c=0x1acd4e0, argc=2, argv=0x7f250a5f0ea0, argvlen=0x7f250a5f0e90)
at /home/package/swoole-src-4.2.8/thirdparty/hiredis/hiredis.c:1007
#5 0x00007f250c9871f5 in redis_request (redis=redis@entry=0x7f250ef1a850, argc=argc@entry=2, argv=argv@entry=0x7f250a5f0ea0,
argvlen=argvlen@entry=0x7f250a5f0e90, return_value=return_value@entry=0x7f2509800200) at /home/package/swoole-src-4.2.8/swoole_redis_coro.cc:926
#6 0x00007f250c9896c9 in sw_redis_command_key (cmd_len=3, cmd=0x7f250c9f70e2 "GET", return_value=0x7f2509800200, execute_data=0x7f25098002b0)
at /home/package/swoole-src-4.2.8/swoole_redis_coro.cc:1047
#7 zim_swoole_redis_coro_get (execute_data=0x7f25098002b0, return_value=0x7f2509800200) at /home/package/swoole-src-4.2.8/swoole_redis_coro.cc:1997

  1. What version of Swoole are you using (php --ri swoole)?

你的版本? 贴出 php --ri swoole 所打印的内容

swoole

swoole support => enabled
Version => 4.2.8
Author => Swoole Group[email: team@swoole.com]
coroutine => enabled
debug => enabled
trace_log => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
http2 => 1.26.0
pcre => enabled
zlib => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.aio_thread_num => 2 => 2
swoole.display_errors => On => On
swoole.use_namespace => On => On
swoole.use_shortname => On => On
swoole.fast_serialize => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608
  1. What is your machine environment used (including the version of kernel & php & gcc)?

你使用的机器系统环境是什么(包括内核、PHP、gcc编译器版本信息)?
可以使用uname -a, php -v, gcc -v 命令打印

Linux php7.2 3.10.0-862.14.4.el7.x86_64 #1 SMP Wed Sep 26 15:12:11 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

PHP 7.2.10 (cli) (built: Sep 29 2018 22:29:42) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
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-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)

@ghost
Copy link

ghost commented Nov 25, 2018

What is $redis->connect('redis.service', 6401);?

@twose twose closed this as completed in 9c073f6 Nov 26, 2018
@twose
Copy link
Member

twose commented Nov 26, 2018

hiredis的错误信息buffer长度是固定的, 太长导致溢出, 需要截断, 已修复.
推荐使用enableCoroutine一键协程化phpredis, 直接使用phpredis.
https://github.com/swoole/swoole-src#-amazing-runtime-hook

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

No branches or pull requests

2 participants