Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[BUG] Upgrade from 2.x: EWMA rate limiter hits WRONGTYPE on sliding-window keys left in Redis

已关闭
#930 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@cameri 已经在做这个了。

开始于 2026年10月24日。

  • #945 来自 @chappie-daemon —— 已合并

评估

难度
4/5
预计耗时
3-5 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
redis, typescript
领域
backend, databases

调研方向

Start by tracing the EWMA rate limiter’s Lua script and the code that builds its Redis keys; the issue names the colliding connection and message key patterns. Check how the existing sliding-window strategy stores those keys and inspect the upgrade notes. Done means upgrading with legacy sorted-set keys no longer causes WRONGTYPE errors, with the behavior covered for both connection and message limits.

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

描述

Describe the bug
After upgrading from 2.x with the existing cache volume, client workers log on every new connection/message:

uncaught error: [ErrorReply: WRONGTYPE Operation against a key holding the wrong kind of value script: <sha>, on @user_script:6.]

2.x used the sliding-window limiter, which stores ${remoteAddress}:connection:${period} and ${client}:message:${period} as sorted sets. Since #476 the default limits.rateLimiter.strategy is ewma, whose Lua script does HGET/HSET on the same key names. The old zset keys stay in Redis until their TTL expires (up to the longest configured period), and until then those clients hit the error path.

To Reproduce

  1. Run 2.x for a while (rate-limit keys accumulate in the cache volume).
  2. Upgrade to 3.x keeping the volume, start the relay.
  3. docker logs nostream shows the WRONGTYPE errors above; redis-cli type <ip>:connection:<period> → zset.

Expected behavior
Upgrading does not require manual Redis cleanup.

System

  • Version: 2.1.0 → 3.4.1, default rateLimiter.strategy: ewma, redis:7.0.5-alpine3.16

Workaround we used
Delete only the conflicting legacy keys (7 058 in our case), after which the errors stopped:

for p in '*:connection:*' '*:message:*'; do
  redis-cli -a "$REDIS_PASSWORD" --scan --pattern "$p" | while read k; do
    [ "$(redis-cli -a "$REDIS_PASSWORD" type "$k")" = zset ] && redis-cli -a "$REDIS_PASSWORD" del "$k"
  done
done

Suggestion
Either namespace the EWMA keys (e.g. ewma: prefix) so they cannot collide with sliding-window keys — this also helps when an operator switches strategy back and forth — or make the EWMA script self-healing:

if redis.call('TYPE', key).ok ~= 'hash' then redis.call('DEL', key) end

plus a line in the upgrade notes.

主要语言
TypeScript
星标
829
派生
234
平均合并
17 小时 6 分钟
30 天内合并 PR
92

环境准备

从这里开始

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

cameri/nostream 的其他 Issue

查看 cameri/nostream 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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