Backport: Fix potential infinite loop in clusterNodeGetMaster (#2830)

Issue #609 is marked as completed (fixed by #651); however, the fix is
only present in versions 8.0 and above.

This PR backports the fix into the 7.2 branch

Signed-off-by: hieu2102 <hieund2102@gmail.com>
This commit is contained in:
hieu2102 2025-11-13 16:18:14 +07:00 committed by GitHub
parent 97b6663c77
commit 4207301f1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 2 deletions

View File

@ -7746,8 +7746,12 @@ unsigned int countKeysInSlot(unsigned int hashslot) {
}
clusterNode *clusterNodeGetMaster(clusterNode *node) {
while (node->slaveof != NULL) node = node->slaveof;
return node;
clusterNode *master = node;
while (master->slaveof != NULL) {
master = master->slaveof;
if (master == node) break;
}
return master;
}
/* -----------------------------------------------------------------------------