Skip to content

Pub sub mode fix#190

Merged
mranney merged 3 commits into
redis:masterfrom
bnoguchi:pub_sub_mode-fix
Apr 30, 2012
Merged

Pub sub mode fix#190
mranney merged 3 commits into
redis:masterfrom
bnoguchi:pub_sub_mode-fix

Conversation

@bnoguchi

Copy link
Copy Markdown
Contributor

Failure will occur in the following scenario:

A single-subscription client (i.e., a client that called subscribe just once before) calls unsubscribe immediately followed by a subscribe (the 2nd call to subscribe). It will fail when it tries to receive the next pmessage/message because the client will be in false pub_sub_mode.

Here is why it will have false pub_sub_mode:

First, the 2nd subscribe sets pub_sub_mode to true during send_command. Next, the unsubscribe's return_reply sets pub_sub_mode to false. The 2nd subscribe's return_reply does not re-set pub_sub_mode back to true. So the result is a client with false pub_sub_mode that fails upon receipt of the next message or pmessage.

This pull request adds both a test to demonstrate the failing scenario and a fix for it that sets pub_sub_mode to true upon receipt of a subscribe reply.

The test demonstrates failure for the following scenario. A single-subscription
client calls unsubscribe immediately followed by a subscribe. It will fail when
it tries to receive the next pmessage/message because the client will be in
false pub_sub_mode. Here is why it is false: First, the 2nd subscribe sets
pub_sub_mode to true during send_command. Next, the unsubscribe's
return_reply sets pub_sub_mode to false. The 2nd subscribe's return_reply does
not re-set pub_sub_mode back to true. So the result is a client with false
pub_sub_mode that fails upon receipt of the next message or pmessage.
@DTrejo

DTrejo commented Apr 28, 2012

Copy link
Copy Markdown
Contributor

Thank you brian!
Test did fail, and your change did fix the problem. All tests still passing.
@mranney, ok to merge?
D

mranney added a commit that referenced this pull request Apr 30, 2012
@mranney mranney merged commit 9e76387 into redis:master Apr 30, 2012
@mranney

mranney commented Apr 30, 2012

Copy link
Copy Markdown
Contributor

Thanks for the fix, @bnoguchi.

mranney added a commit that referenced this pull request Apr 30, 2012
* [GH-190] - pub/sub mode fix (Brian Noguchi)
* [GH-165] - parser selection fix (TEHEK)
* numerous documentation and examples updates
* auth errors emit Errors instead of Strings (David Trejo)
DTrejo pushed a commit that referenced this pull request Apr 30, 2012
Tests for a bug where the client unsubscribes
and then subscribes to a single channel. If the
subscription is sent before the response to the
unsubscribe is received, then the client would
leave pubsub mode when it received the unsubscribe
response and then fail to enter when the subsequent
subscription is processed. This is another test for #190:
#190

Signed-off-by: David Trejo <david.daniel.trejo@gmail.com>
@DTrejo DTrejo mentioned this pull request Apr 30, 2012
supercoder1213 added a commit to supercoder1213/redis that referenced this pull request Feb 1, 2023
Tests for a bug where the client unsubscribes
and then subscribes to a single channel. If the
subscription is sent before the response to the
unsubscribe is received, then the client would
leave pubsub mode when it received the unsubscribe
response and then fail to enter when the subsequent
subscription is processed. This is another test for #190:
redis/node-redis#190

Signed-off-by: David Trejo <david.daniel.trejo@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants