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

block in read when call redisCommand #443

Closed
weingithub opened this issue Jun 29, 2016 · 10 comments
Closed

block in read when call redisCommand #443

weingithub opened this issue Jun 29, 2016 · 10 comments

Comments

@weingithub
Copy link

image

it's the network problem? the redis server address is localhost.

@badboy
Copy link
Contributor

badboy commented Jun 29, 2016

Please provide the error as text, images are not searchable, copyable or accessible.
Please also provide:

  1. What code did you run?
  2. What did you expect to happen?
  3. What happened instead?

@weingithub
Copy link
Author

weingithub commented Jun 29, 2016

(gdb) bt
#0  0x00007f4ebc54482d in read () from /lib64/libpthread.so.0
#1  0x00007f4ebbf0e1b3 in redisBufferRead (c=0x1829040) at hiredis.c:802
#2  0x00007f4ebbf0ecc1 in redisGetReply (c=0x1829040, reply=0x7f4eb2bfc588) at hiredis.c:888
#3  0x00007f4ebbf0fe65 in __redisBlockForReply (c=0x1829040, format=<value optimized out>, ap=<value optimized out>) at hiredis.c:995
#4  redisvCommand (c=0x1829040, format=<value optimized out>, ap=<value optimized out>) at hiredis.c:1005
#5  0x00007f4ebbf0fef8 in redisCommand (c=<value optimized out>, format=<value optimized out>) at hiredis.c:1012
#6  0x000000000040f1ea in SuperSpider::ExecRedisCommand (this=0x7fffd532e920, 
    pcommand=0x7f4ea036a4a8 "sadd www.qidian.com_3 read.qidian.com/BookReader/cF08D_FqdtR7DVpbqm07HA2.aspx", vctresult=std::vector of length 0, capacity 0) at spider.cpp:201
#7  0x00000000004110e0 in SuperSpider::ParseResponse (this=0x7fffd532e920, 
    pdata=0x7f4ea0796fa0 "HTTP/1.1 200 OK\r\nDate: Wed, 29 Jun 2016 09:09:12 GMT\r\nServer: Apache\r\nCache-Control: public\r\nExpires: Wed, 29 Jun 2016 09:18:12 GMT\r\nLast-Modified: Wed, 29 Jun 2016 09:09:12 GMT\r\nTransfer-Encoding: ch"..., len=292196, pCurrent=0x18293e0, url="www.qidian.com/Default.aspx/Book/1003597276.aspx", filename=
    "output/1003597276.aspx") at spider.cpp:658
#8  0x000000000041013b in SuperSpider::GetResponse (this=0x7fffd532e920, url="www.qidian.com/Default.aspx/Book/1003597276.aspx", purl=0x18293e0) at spider.cpp:474
#9  0x000000000040fa3a in SuperSpider::AccessTargetThread (vParam=0x182b4d0) at spider.cpp:379
#10 0x00007f4ebc53daa1 in start_thread () from /lib64/libpthread.so.0
#11 0x00007f4ebb4be93d in clone () from /lib64/libc.so.6
(gdb) f 6
#6  0x000000000040f1ea in SuperSpider::ExecRedisCommand (this=0x7fffd532e920, 
    pcommand=0x7f4ea036a4a8 "sadd www.qidian.com_3 read.qidian.com/BookReader/cF08D_FqdtR7DVpbqm07HA2.aspx", vctresult=std::vector of length 0, capacity 0) at spider.cpp:201
201         redisReply * reply = (redisReply*) redisCommand(m_pRedisContext, pcommand);
(gdb) p pcommand
$1 = 0x7f4ea036a4a8 "sadd www.qidian.com_3 read.qidian.com/BookReader/cF08D_FqdtR7DVpbqm07HA2.aspx"

I call redisCommand function , to run 'sadd www.qidian.com_3 read.qidian.com/BookReader/cF08D_FqdtR7DVpbqm07HA2.aspx' command,

and I expect get redisReply * value,but now ,my program blocked

@weingithub
Copy link
Author

I forgot to say, I call redisCommand () in multi-thread ,did it have influence on this problem?

@badboy
Copy link
Contributor

badboy commented Jun 29, 2016

If you share a single connection context across multiple threads, yes. hiredis is not thread-safe. Bad things will happen if you use it simultaneously from multiple threads.

@popstk
Copy link

popstk commented Dec 26, 2016

@badboy
Hi, I met the same issue with version 0.11.0 in Red Hat 4.4.7-11.
I shared a single connection context across multiple threads, but I use it with a mutex.
And I pstack my process.
There are one thread using the connection context to send command, which block in redisBufferRead.
Another thead blocks in my own mutex, which do not use connection context.

Is connection context thread safe in this situation?

@naugaria7
Copy link

@badboy
Can you respond to @popstk 's query. I am running into a similar issue. I have a connection pool from which threads can borrow RedisContexts. A different thread can pick up the context once it is freed from original thread. Is the Context thread safe in this case?

@peppo65
Copy link

peppo65 commented Jun 4, 2018

@popstk
Hi, I'm also trying to solve the concurrent access to RedisContext by using a mutex (a boost::recursive_mutex to be precise). but doesn't seem to work, as occasionally I get into blocks during read operations. Maybe that serializing accesses to RedisContext from multiple threads doesn't guarantee per se that everything works well... How did you solve the problem?

@popstk
Copy link

popstk commented Jun 5, 2018

@peppo65
I did not solve this problem. Each thread has its own RedisContext instead. ╮(╯_╰)╭
It seems to work if not to share RedisContext between threads , including creation, using and release.

@694917653
Copy link

use this func:
redisSetTimeout

@unrealyx
Copy link

unrealyx commented Jun 9, 2021

@popstk
me too

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

7 participants