You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
redis-cli has a persistent problem where it will just exit on the next command when left idle for too long. It should reconnect instead.
I haven't been able to track down why it happens yet. redis-cli has many exit points (see end) and even with inserting logging before each exit or return, it still just exits without triggering any of the logs/breakpoints.
It's just an immediate drop out of redis-cli back to a command prompt.
Easy to reproduce: open redis-cli to an active server, leave it idle for a few hours (or over night), then try to issue any command. Instead of sending the command, redis-cli just exits.
(exit points):
% grep "exit(1)" redis-cli.c |wc -l
49
Plus, many of the return; statements can cause an exit too if we are returning from the event loop.
Hello Matt, it always happens to me, it is really a pain. Following your advices to reproduce, let's check if I'll be lucky enough to find the issue in a reasonable amount of time.
if (config.interactive) {
/* Filter cases where we should reconnect */
if (context->err == REDIS_ERR_IO && errno == ECONNRESET)
return REDIS_ERR;
if (context->err == REDIS_ERR_EOF)
return REDIS_ERR;
}
cliPrintContextError();
exit(1);
The cliReadReply() call gets a different error from some reason after a long wait, so exits... and context is NULL so no error is printed.
This happens to me, I always assumed its because we have idle timeout set on all redis connections and so unless I'm sending comments often in the CLI it will eventually time out.
@Plasma redis-cli is designed to try to reconnect forever :-) Should never exit. But finally we know what it is. The problem remained there forever since is timeout-ish alike as you already told, and because it only happens after hours. So it needed some focus to track it down.
Oh, and with signal(SIGPIPE, SIG_IGN);, now we get:
127.0.0.1:6379> get a
Error:Broken pipe
matt@ununoctium:~/repos/redis/src%
But, redis-cli.c does have a section to check for connection problems then just re-try:
if (context->err==REDIS_ERR_IO&&errno==ECONNRESET)
We can just throw in a check for errno == EPIPE too and redis-cli should re-connect just like a regular connection loss.
So, I've added an EPIPE check there and I'm testing that fix today (third attempt!). Hopefully now we've found everything needed to stop automatic exits.
I'm often using actual shell pipe, e.g. "redis-cli -p ... monitor | head -n20" to see limited number of live requests on the redis server.
Pretty sure this fix of yours broke that functionality -- now instead of quitting after 20 lines, redis-cli just sits there until killed with another signal.
Should I create a new bug or can this one be reopened?
Activity
antirez commentedon Oct 14, 2014
Hello Matt, it always happens to me, it is really a pain. Following your advices to reproduce, let's check if I'll be lucky enough to find the issue in a reasonable amount of time.
antirez commentedon Oct 14, 2014
A suspicious code path could be: cliPrintContextError() + exit().
If the context is NULL, this is where you can get a silent exit...
Btw I tried to reproduce the issue without waiting 3 hours, without success so far ;-)
mattsta commentedon Oct 14, 2014
Yeah, it's very tricky to reproduce without waiting 5+ hours. Plus, when you test it and it does work, any timers are probably reset!
Maybe open 10 different redis-cli instances and test them incrementally? :) Then at least one failed test won't reset time back to zero for the rest.
antirez commentedon Oct 14, 2014
Ok, this is where I think the issue is:
The cliReadReply() call gets a different error from some reason after a long wait, so exits... and context is NULL so no error is printed.
antirez commentedon Oct 14, 2014
No sorry, it's not NULL, so the exit should still not be totally silent. Argh! :-)
antirez commentedon Oct 15, 2014
@mattsta yes opening 10 should definitely work! And maybe set a break point to the exit syscall in the debugger. I'll try today, thanks.
mattsta commentedon Oct 15, 2014
More data: Just had a failure (no lldb hooked up to this one though, doh), but the return value indiciates a failure due to SIGPIPE:
(See things like http://stackoverflow.com/questions/18880606/socket-connection-getting-closed-abruptly-with-code-141)
So, we can track down where the SIGPIPE happens or just SIG_IGN SIGPIPE :)
antirez commentedon Oct 15, 2014
Bingo! You nailed it. Redis itself does
signal(SIGPIPE, SIG_IGN);.You tracked it, your is the honor of committing the fix :-)
Plasma commentedon Oct 15, 2014
This happens to me, I always assumed its because we have idle timeout set on all redis connections and so unless I'm sending comments often in the CLI it will eventually time out.
antirez commentedon Oct 16, 2014
@Plasma redis-cli is designed to try to reconnect forever :-) Should never exit. But finally we know what it is. The problem remained there forever since is timeout-ish alike as you already told, and because it only happens after hours. So it needed some focus to track it down.
mattsta commentedon Oct 16, 2014
Just caught it in the debugger too:
mattsta commentedon Oct 16, 2014
Oh, and with
signal(SIGPIPE, SIG_IGN);, now we get:But, redis-cli.c does have a section to check for connection problems then just re-try:
We can just throw in a check for
errno == EPIPEtoo and redis-cli should re-connect just like a regular connection loss.So, I've added an EPIPE check there and I'm testing that fix today (third attempt!). Hopefully now we've found everything needed to stop automatic exits.
mattsta commentedon Oct 18, 2014
Finally found proof the fix works.
Here is the error being caught (so we can continue instead of exiting):
And here's the reconnect happening after the failure above:
No more spontaneous exits due to uncaught signals or bad return values!
redis-cli: ignore SIGPIPE network errors
antirez commentedon Oct 30, 2014
Thanks Matt! Merging.
redis-cli: ignore SIGPIPE network errors
redis-cli: ignore SIGPIPE network errors
Fry-kun commentedon Dec 8, 2014
I'm often using actual shell pipe, e.g. "redis-cli -p ... monitor | head -n20" to see limited number of live requests on the redis server.
Pretty sure this fix of yours broke that functionality -- now instead of quitting after 20 lines, redis-cli just sits there until killed with another signal.
Should I create a new bug or can this one be reopened?
badboy commentedon Dec 8, 2014
Yes, the patch now completely ignores the SIGPIPE. Maybe we should only ignore it if we're interactive.
Fry-kun commentedon Dec 8, 2014
yes, sounds like reasonable solution
Only ignore sigpipe in interactive mode
Only ignore sigpipe in interactive mode
Update RedisTimeSeries module to v8.9.81 (#15372)
Update RedisTimeSeries to version 8.11.90 (#15969)