CPU pegged while using createCluster() against AWS ElastiCache Valkey cluster

Description

It seems to me like there is a bug in this code snippet:
https://github.com/redis/node-redis/blob/master/packages/client/lib/cluster/cluster-slots.ts#L481-L489

We use AWS Elasticache Valkey and recently migrated one of our ReplicationGroups to Cluster-compatible mode to distribute the load.

From time to time, we see our clients entering the aforementioned loop with both master.length = 0 and replicas.length = 0 and endlessly spinning completely pegging the CPU.

We have tried using Elasticache's primary endpoint, configuration endpoint and node endpoints to no luck. We are not sure why AWS returns 0 masters/replicas but regardless, code shouldn't even enter this loop when both replicas and masters are empty.

Because when the clients enter this state, it is irrecoverable.

Node.js Version

22.17.x

Redis Server Version

7.x

Node Redis Version

4.x+

Platform

Linux

Logs