ERR
redis
runtime_error
ai_generated
true
运行脚本时出错(调用 f_<sha>):@user_script: <line>:Lua 脚本堆栈溢出
ERR Error running script (call to f_<sha>): @user_script: <line>: Stack overflow in Lua script
ID: redis/lua-script-stack-overflow
75%修复率
82%置信度
1证据数
2023-04-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| redis 7.0 | active | — | — | — |
| redis 7.2 | active | — | — | — |
| redis 6.2 | active | — | — | — |
| redis 5.0 | active | — | — | — |
根因分析
Lua 脚本超过了最大调用堆栈深度,通常是由于深度递归或过多嵌套函数调用。
English
Lua script exceeded the maximum call stack depth, typically due to deep recursion or excessive nested function calls.
官方文档
https://redis.io/docs/latest/develop/interact/programmability/lua-api/解决方案
-
Refactor the Lua script to use iterative loops instead of recursion, e.g., replace recursive function with a while loop: while condition do ... end
-
Reduce the depth of nested function calls by flattening logic or using tail-recursive calls if Lua version supports (Redis Lua 5.1 does not).
无效尝试
常见但无效的做法:
-
95% 失败
Redis does not expose a Lua stack size configuration; the limit is hardcoded.
-
50% 失败
The script execution mechanism is the same; the error is script logic, not caching.
-
80% 失败
Stack overflow is a call depth issue, not a memory allocation issue; more memory does not increase stack depth.