-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
hiredis client hang at redisBufferRead, with timeout option and keepalive option set #593
Comments
This might be a bit tough to test but I'll see if I can replicate the scenario you're describing. As for the threading, it should work as long as you're not attempting to share contexts across multiple threads. |
Thanks for reply. I have read the hiredis code and I think the problem might caused by reconnect. |
have you solve this problem? I meet the same problem when I reset the IPSEC between my hiredis client and redis server, my client program hang until the IPSEC reconnect and the hiredis context->err is the error "REDIS_ERR_IO", I want to find this disconnect as soon as possible instead of when the IPSEC reconnect |
I believe I reproduced the same issue. It seems that after call to redisReconnect you need to re-set timeout using redisSetTimeout, otherwise the client hangs in redisBufferRead. I reproduced this on current master (2d9d775) as well as older version (0.13.3). Here is what I did:
Patch to example.c to reprodice the issue: --- a/examples/example.c
+++ b/examples/example.c
@@ -38,9 +38,24 @@ int main(int argc, char **argv) {
}
exit(1);
}
+ redisSetTimeout(c, timeout);
/* PING server */
reply = redisCommand(c,"PING");
+ if (!reply) {
+ printf("ERROR\n");
+
+ redisReconnect(c);
+// redisSetTimeout(c, timeout); // Uncommenting this line fixes the issue
+ reply = redisCommand(c,"PING");
+
+ // never reaches here
+ if (!reply) {
+ printf("ERROR\n");
+ exit(1);
+ }
+ }
+
printf("PING: %s\n", reply->str);
freeReplyObject(reply); When you run it it only prints ERROR once and hangs:
backtrace:
(and yes, redisReconnect returns 0). |
Should be resolved via #1093 |
Here is how the client program use hiredis to connect redis servers:
The client program callls the redisSetTimeout and redisEnableKeepAlive to set timeout option and activate tcp keepalive.
Here is the stack where the program hang:
My redis servers run in cluster mode by using twem proxy, when this problem occurred, there is one redis server shutdown due to hardware problem, and the MGet command right just sent to this broken redis server.
Unlike the other hang problems reported, my client program has set timeout and keepalive option when connected to redis servers, and although the client program runs in multi-thread task, but would use one exclusive hiredis client context for each thread. So would that be some new problems?
The text was updated successfully, but these errors were encountered: