From 85a239b363591a7f35f66eb8370cabead8545ffa Mon Sep 17 00:00:00 2001 From: Yanqi Lv Date: Fri, 19 Jan 2024 23:03:20 +0800 Subject: [PATCH] Change dictGetSafeIterator to dictGetIterator in pubsub (#12931) In #12838, we misuse the safe iterator of the client dict, so we can't catch the synchronous release of the client if there is a bug. Since we realize that clients (even subscribers) are released with async free, we change the safe iterators of the client dict into unsafe iterators in `pubsub.c`. And I also remove redundant code. --- src/pubsub.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/pubsub.c b/src/pubsub.c index 1a151b96c4..afaf0832fc 100644 --- a/src/pubsub.c +++ b/src/pubsub.c @@ -374,9 +374,8 @@ void pubsubShardUnsubscribeAllChannelsInSlot(unsigned int slot) { while ((de = dictNext(di)) != NULL) { robj *channel = dictGetKey(de); dict *clients = dictGetVal(de); - if (dictSize(clients) == 0) goto cleanup; /* For each client subscribed to the channel, unsubscribe it. */ - dictIterator *iter = dictGetSafeIterator(clients); + dictIterator *iter = dictGetIterator(clients); dictEntry *entry; while ((entry = dictNext(iter)) != NULL) { client *c = dictGetKey(entry); @@ -390,7 +389,6 @@ void pubsubShardUnsubscribeAllChannelsInSlot(unsigned int slot) { } } dictReleaseIterator(iter); -cleanup: server.shard_channel_count--; dictDelete(d, channel); } @@ -529,7 +527,7 @@ int pubsubPublishMessageInternal(robj *channel, robj *message, pubsubtype type) if (de) { dict *clients = dictGetVal(de); dictEntry *entry; - dictIterator *iter = dictGetSafeIterator(clients); + dictIterator *iter = dictGetIterator(clients); while ((entry = dictNext(iter)) != NULL) { client *c = dictGetKey(entry); addReplyPubsubMessage(c,channel,message,*type.messageBulk); @@ -557,7 +555,7 @@ int pubsubPublishMessageInternal(robj *channel, robj *message, pubsubtype type) sdslen(channel->ptr),0)) continue; dictEntry *entry; - dictIterator *iter = dictGetSafeIterator(clients); + dictIterator *iter = dictGetIterator(clients); while ((entry = dictNext(iter)) != NULL) { client *c = dictGetKey(entry); addReplyPubsubPatMessage(c,pattern,channel,message);