summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Svensson <bjorn.a.svensson@est.tech>2022-02-02 22:42:23 +0100
committerBjörn Svensson <bjorn.a.svensson@est.tech>2022-02-02 23:43:21 +0100
commitb6fb548fc65497ce933cfd15b6fd91c700d4b34e (patch)
treec5fdf8ae447a2b58783e0d9512596ddc6b36a5e2
parentf8de9a4bd433791890572f7b9147e685653ddef9 (diff)
Ignore pubsub replies without a channel/pattern
-rw-r--r--async.c4
-rw-r--r--test.c6
2 files changed, 9 insertions, 1 deletions
diff --git a/async.c b/async.c
index 6555114..296d31b 100644
--- a/async.c
+++ b/async.c
@@ -431,8 +431,10 @@ static int __redisGetSubscribeCallback(redisAsyncContext *ac, redisReply *reply,
else
callbacks = ac->sub.channels;
+ /* Ignore replies without a channel/pattern string */
+ if (reply->element[1]->type != REDIS_REPLY_STRING) return REDIS_OK;
+
/* Locate the right callback */
- assert(reply->element[1]->type == REDIS_REPLY_STRING);
sname = sdsnewlen(reply->element[1]->str,reply->element[1]->len);
if (sname == NULL)
goto oom;
diff --git a/test.c b/test.c
index f991ef1..b76b49a 100644
--- a/test.c
+++ b/test.c
@@ -1733,6 +1733,10 @@ void subscribe_channel_a_cb(redisAsyncContext *ac, void *r, void *privdata) {
redisAsyncCommand(ac,unexpected_cb,
(void*)"unsubscribe should not call unexpected_cb()",
"unsubscribe B X A");
+ /* Unsubscribe to patterns, none which we subscribe to */
+ redisAsyncCommand(ac,unexpected_cb,
+ (void*)"punsubscribe should not call unexpected_cb()",
+ "punsubscribe");
/* Send a regular command after unsubscribing, then disconnect */
state->disconnect = 1;
redisAsyncCommand(ac,integer_cb,state,"LPUSH mylist foo");
@@ -1769,6 +1773,8 @@ void subscribe_channel_b_cb(redisAsyncContext *ac, void *r, void *privdata) {
* - subscribe to channel A and B
* - a published message on A triggers an unsubscribe of channel B, X and A
* where channel X is not subscribed to.
+ * - the published message also triggers an unsubscribe to patterns. Since no
+ * pattern is subscribed to the responded pattern element type is NIL.
* - a command sent after unsubscribe triggers a disconnect */
static void test_pubsub_multiple_channels(struct config config) {
test("Subscribe to multiple channels: ");