mirror of https://mirror.osredm.com/root/redis.git
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.
This commit is contained in:
parent
b07174afc2
commit
85a239b363
|
@ -374,9 +374,8 @@ void pubsubShardUnsubscribeAllChannelsInSlot(unsigned int slot) {
|
||||||
while ((de = dictNext(di)) != NULL) {
|
while ((de = dictNext(di)) != NULL) {
|
||||||
robj *channel = dictGetKey(de);
|
robj *channel = dictGetKey(de);
|
||||||
dict *clients = dictGetVal(de);
|
dict *clients = dictGetVal(de);
|
||||||
if (dictSize(clients) == 0) goto cleanup;
|
|
||||||
/* For each client subscribed to the channel, unsubscribe it. */
|
/* For each client subscribed to the channel, unsubscribe it. */
|
||||||
dictIterator *iter = dictGetSafeIterator(clients);
|
dictIterator *iter = dictGetIterator(clients);
|
||||||
dictEntry *entry;
|
dictEntry *entry;
|
||||||
while ((entry = dictNext(iter)) != NULL) {
|
while ((entry = dictNext(iter)) != NULL) {
|
||||||
client *c = dictGetKey(entry);
|
client *c = dictGetKey(entry);
|
||||||
|
@ -390,7 +389,6 @@ void pubsubShardUnsubscribeAllChannelsInSlot(unsigned int slot) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dictReleaseIterator(iter);
|
dictReleaseIterator(iter);
|
||||||
cleanup:
|
|
||||||
server.shard_channel_count--;
|
server.shard_channel_count--;
|
||||||
dictDelete(d, channel);
|
dictDelete(d, channel);
|
||||||
}
|
}
|
||||||
|
@ -529,7 +527,7 @@ int pubsubPublishMessageInternal(robj *channel, robj *message, pubsubtype type)
|
||||||
if (de) {
|
if (de) {
|
||||||
dict *clients = dictGetVal(de);
|
dict *clients = dictGetVal(de);
|
||||||
dictEntry *entry;
|
dictEntry *entry;
|
||||||
dictIterator *iter = dictGetSafeIterator(clients);
|
dictIterator *iter = dictGetIterator(clients);
|
||||||
while ((entry = dictNext(iter)) != NULL) {
|
while ((entry = dictNext(iter)) != NULL) {
|
||||||
client *c = dictGetKey(entry);
|
client *c = dictGetKey(entry);
|
||||||
addReplyPubsubMessage(c,channel,message,*type.messageBulk);
|
addReplyPubsubMessage(c,channel,message,*type.messageBulk);
|
||||||
|
@ -557,7 +555,7 @@ int pubsubPublishMessageInternal(robj *channel, robj *message, pubsubtype type)
|
||||||
sdslen(channel->ptr),0)) continue;
|
sdslen(channel->ptr),0)) continue;
|
||||||
|
|
||||||
dictEntry *entry;
|
dictEntry *entry;
|
||||||
dictIterator *iter = dictGetSafeIterator(clients);
|
dictIterator *iter = dictGetIterator(clients);
|
||||||
while ((entry = dictNext(iter)) != NULL) {
|
while ((entry = dictNext(iter)) != NULL) {
|
||||||
client *c = dictGetKey(entry);
|
client *c = dictGetKey(entry);
|
||||||
addReplyPubsubPatMessage(c,pattern,channel,message);
|
addReplyPubsubPatMessage(c,pattern,channel,message);
|
||||||
|
|
Loading…
Reference in New Issue