-
Notifications
You must be signed in to change notification settings - Fork 23.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
[BUG] SUSCRIBE in RESP3 gets no proper reply, only push #11784
Comments
@zuiderkwast thank you for reporting this. So basically you suggest we should change the 'addReplyPushLen' to 'addReplyArrayLen'? I guess this will also need to handle the unsubscribe and pattern cases. |
i don't think we want (or can afford) to break this now. disclaimer: i didn't think this through much, and it's not my area of expertise. if clients can't handle that in a proper way (creates complications distinguishing between things), then maybe we have to sort it out. |
I'm going to add another vote for "don't change this"; unfortunate? maybe - but: changing it now is just adding a landmine for library authors and comsumers, breaking things when they innocently connect to a different server. Perhaps the way to consider this is more conceptual - as a documentation clarification to https://redis.io/docs/manual/pubsub/
and perhaps with a RESP3 request/response example where relevant, rather than just RESP2 (obviously after checking whether this is indeed the case for all of This does have the side-effect that clients need to special-case |
I agree - this isn't how proper commands should behave, so an "+OK" can definitely make this better. |
@zuiderkwast can you please explain what you mean by "Clients get out of sync due to this"? if anything, what's weird is that UNSUBSCRIBE also replies with push. the problem here is that the client is considered CLIENT_PUBSUB while it is subscribed to at least one channel. that means that if I execute UNSUBSCRIBE with no args (or the UNSUBSCRIBE that causes the client not to be subscribed to anything anymore) i get a push reply while not in pusub mode. so yes, it does look weird, but does it cause an actual issue with clients? |
There are many variants to argue for one or the other. I'm for leaving things as-is. Receiving the confirmation as Pub/Sub push seems a better design because the subscription confirmation arrives once Redis is ready with subscribing. Imagine that Redis could require (somewhere in the future) more work than adding subscribers to a subscription table (i. e. doing actual I/O). Once the subscription process is done, Redis returns and confirms the channel/pattern subscription instead of immediately confirming the command. I understand the stance of
as an improper client-side expectation might not be met. However, instead of changing every client available, I suggest fixing the one client that can't handle subscribe commands. |
I do not think this is a resp3 protocol intended issue but simply a bug. |
Thanks all for jumping in.
@ranshid No, since one SUBSCRIBE ch1 ch2 produces two push replies (one for each channel), so if we change to an array, we'd send two array responses to one command which would also break the request/response model. Rather an (in-band) +OK response to the subscribe command.
@guybe7 A naive client would offload any push messages, for example to a callback function that handles them or putting them in a separate queue on the side, and then continue the request/response flow, expecting one response for each command sent to Redis. A push message can come any time when some other reply is expected. That's why they're called out-of-band. When a client sends a
I think @mgravell put this very well:
and if we do fix it in Redis 8, bumping the resp version to RESP4 could be a sensible idea too.. or we just don't fix it, just document it well. |
Isn't that the case for multi bulk reply in resp2? we can place an array of arrays for each channel. I still think that having an indication of how many channels this client is subscribed to is something we would like to preserve |
@ranshid In RESP2, for |
Not really I only suggested that returning array replies is somewhat the same as in resp2. I think that it if fine to keep things as they are and make sure to document it, but having a separate indication for each channel can be helpful someday (lets say we would like to indicate only the channels the user was able to subscribe to and on which he had errors) |
I think we can conclude: Don't fix it. We can't break existing clients. I just wish the RESP3 behavior for various commands were documented. This is not for just one client, but for clients in general, to make it as clear as possible how they should work. The only command that actually mentions RESP3 is HELLO afaik. Another example is MONITOR. It replies with +OK and then it doesn't use push but every monitored command comes as a simple string. This too requires special handling in clients. Example:
|
Solved by documentation update. |
I consider the current behaviour a bug because it makes it impossible to implement async clients without adding some heuristics. |
@mzimbres we all agree. but imagine what you'll have to do if we fix it? |
Describe the bug
After sending SUBSCRIBE and UNSUBSCRIBE (and P and S variants), the message
["subscribe", "ch1", 1]
comes as a push message, not a proper reply. If "SUBSCRIBE ch1 ch2", you get two push messages, but no reply. Clients get out of sync due to this.To reproduce
Expected behavior
SUBSCRIBE should get +OK or something like that, so that each command gets a reply. (Push are out-of-band.)
Additional information
This was reported in #7026, which was assumed to be a problem in redis-cli, but it has nothing to do with redis-cli.
I guess we can't fix this now, so perhaps it should instead be clearly documented? RESP3-capable clients need to compensate for this or else they will get out of sync...
The text was updated successfully, but these errors were encountered: