Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

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

未關閉
#930 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
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
平均合併
16 小時 13 分鐘
30 天內合併 PR
74

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

cameri/nostream 的其他 Issue

查看 cameri/nostream 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。