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

- **ID:** `redis/lua-script-deadlock-detected`
- **Domain:** redis
- **Category:** runtime_error
- **Error Code:** `ERM`
- **Verification:** ai_generated
- **Fix Rate:** 78%

## Root Cause

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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 6.0 | active | — | — |
| 7.0 | active | — | — |
| 7.2 | active | — | — |

## Workarounds

1. **Run 'SCRIPT KILL' if the script has not performed any writes (check with 'SCRIPT DEBUG'). If writes occurred, use 'SHUTDOWN NOSAVE' to stop Redis.** (85% success)
   ```
   Run 'SCRIPT KILL' if the script has not performed any writes (check with 'SCRIPT DEBUG'). If writes occurred, use 'SHUTDOWN NOSAVE' to stop Redis.
   ```
2. **Add a loop counter or use 'redis.setresp(3)' to limit iterations. Example: 'local i = 0; while i < 1000 do redis.call("PING"); i = i + 1 end'.** (90% success)
   ```
   Add a loop counter or use 'redis.setresp(3)' to limit iterations. Example: 'local i = 0; while i < 1000 do redis.call("PING"); i = i + 1 end'.
   ```

## Dead Ends

- **** — Only works if script hasn't written data; otherwise, Redis forces shutdown. (40% fail)
- **** — Masks the problem; script may still hang indefinitely, blocking other operations. (70% fail)
- **** — Causes downtime and potential data loss; does not fix the script logic. (60% fail)
