Fix crash caused by pubsubShardUnsubscribeAllChannelsInSlot not deleting the client (#12896)

The code does not delete the corresponding node when traversing clients,
resulting in a loop, causing the dictDelete() == DICT_OK assertion to
fail.

In addition, did a cleanup, in the dictCreate scenario, we can avoid a
dictFind call since the dict is empty.

Issue was introduced in #12804.
This commit is contained in:
Binbin 2023-12-28 14:32:51 +08:00 committed by GitHub
parent 5b1fe925f2
commit 99c468c38c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -295,8 +295,10 @@ int pubsubSubscribeChannel(client *c, robj *channel, pubsubtype type) {
d_ptr = type.serverPubSubChannels(slot);
if (*d_ptr == NULL) {
*d_ptr = dictCreate(&keylistDictType);
de = NULL;
} else {
de = dictFind(*d_ptr, channel);
}
de = dictFind(*d_ptr, channel);
if (de == NULL) {
clients = listCreate();
dictAdd(*d_ptr, channel, clients);
@ -387,6 +389,7 @@ void pubsubShardUnsubscribeAllChannelsInSlot(unsigned int slot) {
if (clientTotalPubSubSubscriptionCount(c) == 0) {
unmarkClientAsPubSub(c);
}
listDelNode(clients, ln);
}
server.shard_channel_count--;
dictDelete(d, channel);