cluster slots not rediscovered on scale-down cluster

未关闭
#2,806 5 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
node.js, redis, typescript

调研方向

从 packages/client/lib/cluster/index.ts 开始,重点查看针对 MOVED 和 ASK 回复所示的 #slots.rediscover() 调用。重现 reshard、del-node 和 shutdown 序列,然后跟踪过时的集群拓扑如何仍处于活动状态。当 scale-down 情况刷新 slots 并避免报告的 “connection closed” 错误时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

Bug
Description

#slots.rediscover() is correctly called when MOVED or ASK reply is received:

https://github.com/redis/node-redis/blob/6f79b49f731a1aaf57f42e16ea72774f062e57a1/packages/client/lib/cluster/index.ts#L271

https://github.com/redis/node-redis/blob/6f79b49f731a1aaf57f42e16ea72774f062e57a1/packages/client/lib/cluster/index.ts#L256

there is a problem / race-condition on scale-down cluster (rebalance hash slots away, forget node, shutdown):

#slots.rediscover() might never be called, if the leaving node has not been queried (after it's slots migrated away) before shutdown (hence it never got a chance to reply with MOVED and trigger a rediscover)

this results in connection closed errors, because node-redis cluster.#slots is keeping a client active for an outdated cluster topology.

steps to reproduce:

  1. start a redis cluster
  2. create node-redis client and connect
  3. redis-cli reshard all slots away from a redis cluster node
  4. redis-cli del-node the now empty node, then shutdown
  5. node-redis client execute command for a key, which is sharded the (now shutdown) node
  6. connection closed error

an option to fix this would be to provide an option for a slot refresh interval (ioredis does this too), will send a pull request

Node.js Version

No response

Redis Server Version

No response

Node Redis Version

No response

Platform

No response

Logs

No response

主要语言
TypeScript
星标
17.6k
派生
2k
平均合并
1 天 22 小时
30 天内合并 PR
62

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

redis/node-redis 的其他 Issue

查看 redis/node-redis 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。