ERM redis runtime_error ai_generated partial

检测到 LUA 脚本死锁:脚本 <sha> 阻塞了 <seconds> 秒

ERR LUA script deadlock detected: script <sha> blocked for <seconds> seconds

ID: redis/lua-script-deadlock-detected

其他格式: JSON · Markdown 中文 · English
78%修复率
88%置信度
1证据数
2023-05-18首次发现

版本兼容性

版本状态引入弃用备注
6.0 active
7.0 active
7.2 active

根因分析

Lua 脚本进入无限循环或在资源上阻塞(例如,循环内的 Redis.call),超过了 lua-time-limit,触发死锁警告。

English

A Lua script entered an infinite loop or blocked on a resource (e.g., Redis.call inside a loop), exceeding the lua-time-limit and triggering a deadlock warning.

generic

官方文档

https://redis.io/docs/latest/programmability/eval-intro/

解决方案

  1. 如果脚本未执行任何写入(使用 'SCRIPT DEBUG' 检查),运行 'SCRIPT KILL'。如果已写入,使用 'SHUTDOWN NOSAVE' 停止 Redis。
  2. 添加循环计数器或使用 'redis.setresp(3)' 限制迭代次数。示例:'local i = 0; while i < 1000 do redis.call("PING"); i = i + 1 end'。

无效尝试

常见但无效的做法:

  1. 40% 失败

    Only works if script hasn't written data; otherwise, Redis forces shutdown.

  2. 70% 失败

    Masks the problem; script may still hang indefinitely, blocking other operations.

  3. 60% 失败

    Causes downtime and potential data loss; does not fix the script logic.