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
PING not allowed while subscribing #420
Comments
Approved, however when you are in this mode PING should not reply with a standard reply but should send you a PONG "message" in the usual Pub/Sub protocol mode. |
@za-creature, I think that a client, that opens up a socket to the redis-server, it's aware if its socket is readable / writable, open / closed; I do not have to send a PING command ( with redis protocol ) to test if the connection is alive. @antirez Interesting, any idea on what channel ( subscribed by the client ) PONG will be "published"? |
@rootslab |
Hello @za-creature, probably I misunderstood this sentence: 'there is no way for the client to determinates if the connection is still alive' If you're talking about the service connection to REDIS, You are absolutely right. Otherwise, If we talk about testing the liveness of the network connection, you can use the socket (TCP) keepalive as usual. About the workaround, for now my solutions are :
The proposed solution by @antirez is interesting, it breaks a little the redis client-server Pub/Sub mode; a little question will arise: in your opinion, on what channel the PING reply will be published? |
@rootslab I was talking about the network connection, but you are right about keep-alives; I just found out that setsockopt can be used to configure the keep-alive parameters on a per socket basis. Previously, I thought that they can only be set globally by writing to /proc, and that requires root access (unfeasible imo). I don't really know what you meant by service connection; as far as I know, Redis uses a single socket for communication. Or are you referring to detecting errors if the Redis server is frozen for some reason? Because crashes are handled by the operating system (all open sockets are closed automatically on process termination, and the remote end receives a SIGHUP or equivalent) Lastly, yes, both of your solutions work (I've actually implemented the first one), but I strongly believe that workarounds are a bad coding practice, and should be avoided if at all possible. Subscribing to a channel twice again, works, but is counter-intuitive. As for the PONG reply, I don't really know; maybe a reserved channel name like 'redis', but that would break backward compatibility. Or a "null" channel name that cannot be subscribed to anyway. This could also be implemented in a heartbeat-fashion (the way AMQP does it) in which the server sends these messages in a timely fashion chosen by the client, but that would break compatibility with existing clients that will have to handle the out of band heartbeat frames. |
@za-creature for service connection, I simply mean : the aliveness of the service which the (network) socket is connected to. |
@za-creature @antirez If redis-server creates a default read-only channel, a client could SUBSCRIBE to that channel, as usual, to test if the service is up. |
@rootslab Yeah, that's what I thought. It wasn't immediately obvious to me because I usually like to think of the two situations (network error vs service error) as the same one for simplicity, as the code to handle them is almost always the same (close the connection, try again later or log/display an error message) |
@za-creature |
Moved to 3.0 milestone, not a priority for 2.6, we are too near RC1. Thanks. I'll comment on the issue again in a few weeks. |
After further investigation, the TCP keep-alive mechanism can only be used on Linux 2.4+ |
I think the server should allow the client to send PING to detect connection liveness in Pub/Sub mode. Otherwise, the client cannot immediately recover from an occasional connection broken. |
oh,leaning! |
bump! This would solve some troubles I have with redis. |
Thanks for raising this again in the issues list, I'll address this before the end of the week. Proposed solution:
In theory it could be cool to automatically send pings to idle connections from time to time, however this has issues with backward compatibility. However at a latter time when most clients will implement PING in the context of Pub/Sub this will be possible. Please comment ASAP if you are not happy with the proposal. |
Implementing the proposed solution (see my last comment) today, please PING me if you have some different idea. Btw before acting I'm going to re-read the whole thread... |
PING can now be called with an additional arugment, behaving exactly like the ECHO command. PING can now also be called in Pub/Sub mode (with one more more subscriptions to channels / patterns) in order to trigger the delivery of an asynchronous pong message with the optional payload. This fixes issue #420.
Implemented, not closing for lack of tests (work in progress). |
PING can now be called with an additional arugment, behaving exactly like the ECHO command. PING can now also be called in Pub/Sub mode (with one more more subscriptions to channels / patterns) in order to trigger the delivery of an asynchronous pong message with the optional payload. This fixes issue #420.
PING can now be called with an additional arugment, behaving exactly like the ECHO command. PING can now also be called in Pub/Sub mode (with one more more subscriptions to channels / patterns) in order to trigger the delivery of an asynchronous pong message with the optional payload. This fixes issue #420.
This behavioral change breaks hiredis library. Hiredis does not expect such command to return non-error response, causing |
Sounds like a bug in hiredis. Can you fill an issue in https://github.com/redis/hiredis and provide a small test case? I can take care of that then. |
@badboy I tested, and in older version of hiredis (0.10.x), it crashes upon receiving "pong" response in subscribing mode (in async.c), and in latest master version of hiredis, it no longer crashes, but it silently discarded the "pong" response, so that the callback of the "ping" command is never called. I will need to find time to produce a test case, because it involves async I/O, and my current code base is very large. I will custom write a slimmer test case for this, maybe within a couple of weeks. Thanks! |
Implemented into unstable, will be part of Redis 3.2. Closed. |
Why i cannot issue PING or unsubscribe from redis-cli once subscribed to event. |
@aidevr Because |
以subscribe為例而不是ping,是因為redid要2.8.17以上才支援對已經subscribed的connection回應ping,但 我們用的是2.6 redis/redis#420 redis/go-redis#205
This has previously been waiting on redis/redis#420
This has previously been waiting on redis/redis#420
In the current implementation (tested on 2.4.7) redis does not allow ping commands when the client is in subscribe mode.
I believe this should be changed because currently, there is no way for the client to determine if the connection is still alive while subscribing to one or more queues, and no message has been posted for a long time.
The text was updated successfully, but these errors were encountered: