BUSY: Server is blocked by a long script
A Lua script is still running and Redis is single-threaded: until it ends or is killed, only SCRIPT KILL and SHUTDOWN NOSAVE are accepted.
- Error prefix
BUSY- Категория
- Data types and commands
Что это значит
Redis executes commands in one thread. A Lua script that runs too long, an accidental infinite loop being the classic case, blocks that thread, and every other client gets BUSY for its commands. The two escape hatches are named in the message: SCRIPT KILL from another connection stops the script if it has not written anything, and SHUTDOWN NOSAVE stops the server when it has, because a script that is mid-write cannot be undone safely.
The reply tells you the state you are in: if the script already performed writes, SCRIPT KILL refuses and the only way out is SHUTDOWN NOSAVE, losing unsaved data since the last save. That is why unbounded loops in scripts deserve the same review as unbounded loops anywhere else.
Распространённые причины
- A Lua script with an unbounded loop, or a scan that never reaches its end condition.
- A script calling an expensive redis.call repeatedly against a large keyspace.
- A Redis Function (7+) stuck the same way; the matching kill command is FUNCTION KILL.
Find the cause
CONFIG GET busy-reply-threshold # How long a script may run before BUSY replies start (milliseconds, default 5000). Answered only when no script is blocking the server. SCRIPT KILL # The server's reply tells you whether a kill is possible. CLIENT LIST is refused with BUSY while the script runs, so it cannot locate the connection at that point.
Как исправить
-
From a second connection, kill the script if it has not written:
SCRIPT KILL # OK - the blocked clients resume
-
If SCRIPT KILL refuses because the script already wrote, and the dataset is disposable, the last resort is:
SHUTDOWN NOSAVE
-
Fix the script afterwards: bound every loop, limit ranges, and test long scripts on a scratch instance first.
Other ways to handle it
Keep scripts short and move large loops into the client, where blocking one thread is not the price. Set busy-reply-threshold low in development so runaway scripts surface in testing, and reach for Redis Functions only with the same loop discipline.
Безопасное воспроизведение
Run this only against a scratch instance: until SCRIPT KILL lands, that server answers nothing else.
redis-server --port 7304 --save '' & redis-cli -p 7304 EVAL "while true do end" 0 & redis-cli -p 7304 PING # (error) BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE. redis-cli -p 7304 SCRIPT KILL # OK
Вопросы
SCRIPT KILL says the script already wrote. Now what?
The script cannot be stopped mid-write. The options in the message are the whole truth: wait for it to finish, or SHUTDOWN NOSAVE and lose data since the last save.
Does BUSY mean the server crashed?
No. Redis is alive and single-threaded, waiting on your script. That is exactly why every other client sees BUSY.
Связанные ошибки
NOSCRIPTScript SHA1 is not cachedSQLITE_BUSYSQLite: база данных заблокирована57014PostgreSQL: отмена выполнения запроса
More data types and commands errors
WRONGTYPEThe key holds a different data typeERR unknown commandRedis does not know this commandERR wrong number of argumentsArgument count is wrongEXECABORTTransaction discarded after an errorERR invalid expire timeExpire value is out of range
Код и текст сообщения взяты из Redis documentation and source code. Смотрите весь Redis error list или поиск по всем ошибкам баз данных.
Work on Redis in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for Redis and the other databases you use.
Текст и данные на этой странице: CC BY 4.0, с указанием SQLly (sqlly.app). Код и фрагменты SQL: MIT. Подробнее о лицензии Цитируемый текст сообщений об ошибках принадлежит производителю СУБД.