BUSY error

A Lua script or function has run for too long, and Redis is blocked until it ends.

Redis returns this error when a Lua script or function has run for longer than the busy-reply-threshold setting, which is 5 seconds by default. While a script runs, Redis doesn't run any other command. So instead of making other clients wait, Redis answers almost every command with this error, even PING.

BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.

For a function, the message names FUNCTION KILL instead of SCRIPT KILL. A module command that runs for a long time causes a similar error: BUSY Redis is busy running a module command.

In client libraries

Client libraryException or error typeMessage
redis-py ResponseError BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.
Jedis JedisBusyException BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.
node-redis SimpleError
Test with err.message.startsWith('BUSY')
BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.
Lettuce
The async API wraps the exception in an ExecutionException (get()) or a CompletionException (join()).
RedisBusyException BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.
go-redis redis.Error
Test with redis.HasErrorPrefix(err, "BUSY")
BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.
ioredis ReplyError
Test with err.message.startsWith('BUSY')
BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.
StackExchange.Redis
NRedisStack uses StackExchange.Redis, so it raises the same exceptions. The sync and async APIs raise the same exceptions.
RedisConnectionException It was not possible to connect to the redis server(s). Error connecting right now. To allow this multiplexer to continue retrying until it's able to connect, use abortConnect=false in your connection string or AbortOnConnectFail=false; in your code.
StackExchange.Redis sends commands when it connects, and the server refused them while a script ran, so a new connection fails.
Predis Predis\Response\ServerException
Test with $e->getErrorType() === 'BUSY'
BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.
redis-rb Redis::CommandError BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE. (redis://<host>:<port>)
redis-rs
The sync and async APIs raise the same errors.
ErrorKind::Extension
Test with err.code() == Some("BUSY")
"BUSY": Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.

Example

While another client runs a script that never ends:

> GET mykey
(error) BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.
> SCRIPT KILL
OK

How to fix it

  1. Stop the script with SCRIPT KILL, or stop a function with FUNCTION KILL. The client that ran the script then gets an error that starts with ERR Script killed by user with SCRIPT KILL.

  2. If the script has already changed data, Redis can't stop it, because that would leave the change half done. SCRIPT KILL then fails:

    UNKILLABLE Sorry the script already executed write commands against the dataset. You can either wait the script termination or kill the server in a hard way using the SHUTDOWN NOSAVE command.
    

    You can either wait for the script to finish, or stop the server with SHUTDOWN NOSAVE. SHUTDOWN NOSAVE loses all changes that weren't saved to disk.

  3. Change the script so that it can't run this long. Common causes are a loop that never ends, and a script that processes too many keys or elements in one call. Split large jobs into several smaller calls.

See Maximum execution time.

RATE THIS PAGE
Back to top ↑