skip to Main Content

Since Redis 6.2.7 (and Redis 7) an existing Lua script stopped working with the error message:

"ERR user_script:6: Attempt to modify a readonly table script: 2f405679dab26da46ec86d29bded48f66a99ff64, on @user_script:6."

The script is working fine with Redis 6.2.6. I did not find any breaking changes in the last Redis release notes.

Any clue ? Thanks !!

Here’s the script:

-- returns valid task ID if successfull, nil if no tasks

local tenantId = unpack(ARGV)
local activeTenantsSet, activeTenantsList, tenantQueue = unpack(KEYS)

-- next task lua based function - return nil or taskId
function next ()
    local task = redis.call('ZPOPMAX', tenantQueue)
    if table.getn(task) == 0 then
        redis.call('SREM', activeTenantsSet, tenantId)
        redis.call('LREM', activeTenantsList, 0, tenantId)
        return nil
    end
    redis.call('SADD', activeTenantsSet, tenantId)
    redis.call('RPUSH', activeTenantsList, tenantId)
    return task[1]
end

-------------
return next()

2

Answers


  1. try adding ‘local’ in front of ‘function next’

    local function next ()
    ...
    
    Login or Signup to reply.
  2. There’s a fix for this in a new version of Sentry (the patch also applies cleanly to the lua scripts going back to some older versions):
    https://github.com/getsentry/sentry/pull/34416/commits/7c57fe7b17f613fecc47a56c22fff3a20a958496

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search