[BUG] redis: script tried accessing undeclared key #885

Closed
opened 2026-02-04 23:17:30 +03:00 by OVERLORD · 3 comments
Owner

Originally created by @uhthomas on GitHub (May 23, 2023).

The bug

immich-server cannot start and fails with this error:

/usr/src/app/node_modules/redis-parser/lib/parser.js:179
    return new ReplyError(string)
           ^

ReplyError: ERR Error running script (call to 8f55ae4a3be429c6d38c5d5db3e80edf89197b64): @user_script:56: script tried accessing undeclared key
    at parseError (/usr/src/app/node_modules/redis-parser/lib/parser.js:179:12)
    at parseType (/usr/src/app/node_modules/redis-parser/lib/parser.js:302:14) {
  command: {
    name: 'eval',
    args: [
      '--[[\n' +
        '  Adds a job to the queue by doing the following:\n' +
        '    - Increases the job counter if needed.\n' +
        '    - Creates a new job key with the job data.\n' +
        '\n' +
        '    - if delayed:\n' +
        '      - computes timestamp.\n' +
        '      - adds to delayed zset.\n' +
        "      - Emits a global event 'delayed' if the job is delayed.\n" +
        '    - if not delayed\n' +
        '      - Adds the jobId to the wait/paused list in one of three ways:\n' +
        '         - LIFO\n' +
        '         - FIFO\n' +
        '         - prioritized.\n' +
        '      - Adds the job to the "added" list so that workers gets notified.\n' +
        '\n' +
        '    Input:\n' +
        "      KEYS[1] 'wait',\n" +
        "      KEYS[2] 'paused'\n" +
        "      KEYS[3] 'meta-paused'\n" +
        "      KEYS[4] 'id'\n" +
        "      KEYS[5] 'delayed'\n" +
        "      KEYS[6] 'priority'\n" +
        '\n' +
        '      ARGV[1]  key prefix,\n' +
        '      ARGV[2]  custom id (will not generate one automatically)\n' +
        '      ARGV[3]  name\n' +
        '      ARGV[4]  data (json stringified job data)\n' +
        '      ARGV[5]  opts (json stringified job opts)\n' +
        '      ARGV[6]  timestamp\n' +
        '      ARGV[7]  delay\n' +
        '      ARGV[8]  delayedTimestamp\n' +
        '      ARGV[9]  priority\n' +
        '      ARGV[10] LIFO\n' +
        '      ARGV[11] token\n' +
        ']]\n' +
        'local jobId\n' +
        'local jobIdKey\n' +
        'local rcall = redis.call\n' +
        '\n' +
        'local jobCounter = rcall("INCR", KEYS[4])\n' +
        '\n' +
        'if ARGV[2] == "" then\n' +
        '  jobId = jobCounter\n' +
        '  jobIdKey = ARGV[1] .. jobId\n' +
        'else\n' +
        '  jobId = ARGV[2]\n' +
        '  jobIdKey = ARGV[1] .. jobId\n' +
        '  if rcall("EXISTS", jobIdKey) == 1 then\n' +
        '    return jobId .. "" -- convert to string\n' +
        '  end\n' +
        'end\n' +
        '\n' +
        '-- Store the job.\n' +
        'rcall("HMSET", jobIdKey, "name", ARGV[3], "data", ARGV[4], "opts", ARGV[5], "timestamp", ARGV[6], "delay", ARGV[7], "priority", ARGV[9])\n' +
        '\n' +
        '-- Check if job is delayed\n' +
        'local delayedTimestamp = tonumber(ARGV[8])\n' +
        'if(delayedTimestamp ~= 0) then\n' +
        '  local timestamp = delayedTimestamp * 0x1000 + bit.band(jobCounter, 0xfff)\n' +
        '  rcall("ZADD", KEYS[5], timestamp, jobId)\n' +
        '  rcall("PUBLISH", KEYS[5], delayedTimestamp)\n' +
        'else\n' +
        '  local target\n' +
        '\n' +
        '  -- Whe check for the meta-paused key to decide if we are paused or not\n' +
        '  -- (since an empty list and !EXISTS are not really the same)\n' +
        '  local paused\n' +
        '  if rcall("EXISTS", KEYS[3]) ~= 1 then\n' +
        '    target = KEYS[1]\n' +
        '    paused = false\n' +
        '  else\n' +
        '    target = KEYS[2]\n' +
        '    paused = true\n' +
        '  end\n' +
        '\n' +
        '  -- Standard or priority add\n' +
        '  local priority = tonumber(ARGV[9])\n' +
        '  if priority == 0 then\n' +
        '      -- LIFO or FIFO\n' +
        '    rcall(ARGV[10], target, jobId)\n' +
        '  else\n' +
        '    -- Priority add\n' +
        '    rcall("ZADD", KEYS[6], priority, jobId)\n' +
        '    local count = rcall("ZCOUNT", KEYS[6], 0, priority)\n' +
        '\n' +
        '    local len = rcall("LLEN", target)\n' +
        '    local id = rcall("LINDEX", target, len - (count-1))\n' +
        '    if id then\n' +
        '      rcall("LINSERT", target, "BEFORE", id, jobId)\n' +
        '    else\n' +
        '      rcall("RPUSH", target, jobId)\n' +
        '    end\n' +
        '\n' +
        '  end\n' +
        '\n' +
        '  -- Emit waiting event (wait..ing@token)\n' +
        '  rcall("PUBLISH", KEYS[1] .. "ing@" .. ARGV[11], jobId)\n' +
        'end\n' +
        '\n' +
        'return jobId .. "" -- convert to string\n',
      '6',
      'immich_bull:search-queue:wait',
      'immich_bull:search-queue:paused',
      'immich_bull:search-queue:meta-paused',
      'immich_bull:search-queue:id',
      'immich_bull:search-queue:delayed',
      'immich_bull:search-queue:priority',
      'immich_bull:search-queue:',
      '',
      'search-index-assets',
      '{}',
      '{"attempts":3,"removeOnComplete":true,"removeOnFail":false,"delay":0,"timestamp":1684864556479}',
      '1684864556479',
      '0',
      '0',
      '0',
      'LPUSH',
      '6a94d159-4774-413f-9ba4-007d56cfd744'
    ]
  }
}

Node.js v18.16.0

The OS that Immich Server is running on

Kubernetes

Version of Immich Server

1.57.1

Version of Immich Mobile App

N/A

Platform with the issue

  • Server
  • Web
  • Mobile

Your docker-compose.yml content

N/A

Your .env content

N/A

Reproduction steps

I'm not sure, sorry.

Additional information

No response

Originally created by @uhthomas on GitHub (May 23, 2023). ### The bug `immich-server` cannot start and fails with this error: ``` /usr/src/app/node_modules/redis-parser/lib/parser.js:179 return new ReplyError(string) ^ ReplyError: ERR Error running script (call to 8f55ae4a3be429c6d38c5d5db3e80edf89197b64): @user_script:56: script tried accessing undeclared key at parseError (/usr/src/app/node_modules/redis-parser/lib/parser.js:179:12) at parseType (/usr/src/app/node_modules/redis-parser/lib/parser.js:302:14) { command: { name: 'eval', args: [ '--[[\n' + ' Adds a job to the queue by doing the following:\n' + ' - Increases the job counter if needed.\n' + ' - Creates a new job key with the job data.\n' + '\n' + ' - if delayed:\n' + ' - computes timestamp.\n' + ' - adds to delayed zset.\n' + " - Emits a global event 'delayed' if the job is delayed.\n" + ' - if not delayed\n' + ' - Adds the jobId to the wait/paused list in one of three ways:\n' + ' - LIFO\n' + ' - FIFO\n' + ' - prioritized.\n' + ' - Adds the job to the "added" list so that workers gets notified.\n' + '\n' + ' Input:\n' + " KEYS[1] 'wait',\n" + " KEYS[2] 'paused'\n" + " KEYS[3] 'meta-paused'\n" + " KEYS[4] 'id'\n" + " KEYS[5] 'delayed'\n" + " KEYS[6] 'priority'\n" + '\n' + ' ARGV[1] key prefix,\n' + ' ARGV[2] custom id (will not generate one automatically)\n' + ' ARGV[3] name\n' + ' ARGV[4] data (json stringified job data)\n' + ' ARGV[5] opts (json stringified job opts)\n' + ' ARGV[6] timestamp\n' + ' ARGV[7] delay\n' + ' ARGV[8] delayedTimestamp\n' + ' ARGV[9] priority\n' + ' ARGV[10] LIFO\n' + ' ARGV[11] token\n' + ']]\n' + 'local jobId\n' + 'local jobIdKey\n' + 'local rcall = redis.call\n' + '\n' + 'local jobCounter = rcall("INCR", KEYS[4])\n' + '\n' + 'if ARGV[2] == "" then\n' + ' jobId = jobCounter\n' + ' jobIdKey = ARGV[1] .. jobId\n' + 'else\n' + ' jobId = ARGV[2]\n' + ' jobIdKey = ARGV[1] .. jobId\n' + ' if rcall("EXISTS", jobIdKey) == 1 then\n' + ' return jobId .. "" -- convert to string\n' + ' end\n' + 'end\n' + '\n' + '-- Store the job.\n' + 'rcall("HMSET", jobIdKey, "name", ARGV[3], "data", ARGV[4], "opts", ARGV[5], "timestamp", ARGV[6], "delay", ARGV[7], "priority", ARGV[9])\n' + '\n' + '-- Check if job is delayed\n' + 'local delayedTimestamp = tonumber(ARGV[8])\n' + 'if(delayedTimestamp ~= 0) then\n' + ' local timestamp = delayedTimestamp * 0x1000 + bit.band(jobCounter, 0xfff)\n' + ' rcall("ZADD", KEYS[5], timestamp, jobId)\n' + ' rcall("PUBLISH", KEYS[5], delayedTimestamp)\n' + 'else\n' + ' local target\n' + '\n' + ' -- Whe check for the meta-paused key to decide if we are paused or not\n' + ' -- (since an empty list and !EXISTS are not really the same)\n' + ' local paused\n' + ' if rcall("EXISTS", KEYS[3]) ~= 1 then\n' + ' target = KEYS[1]\n' + ' paused = false\n' + ' else\n' + ' target = KEYS[2]\n' + ' paused = true\n' + ' end\n' + '\n' + ' -- Standard or priority add\n' + ' local priority = tonumber(ARGV[9])\n' + ' if priority == 0 then\n' + ' -- LIFO or FIFO\n' + ' rcall(ARGV[10], target, jobId)\n' + ' else\n' + ' -- Priority add\n' + ' rcall("ZADD", KEYS[6], priority, jobId)\n' + ' local count = rcall("ZCOUNT", KEYS[6], 0, priority)\n' + '\n' + ' local len = rcall("LLEN", target)\n' + ' local id = rcall("LINDEX", target, len - (count-1))\n' + ' if id then\n' + ' rcall("LINSERT", target, "BEFORE", id, jobId)\n' + ' else\n' + ' rcall("RPUSH", target, jobId)\n' + ' end\n' + '\n' + ' end\n' + '\n' + ' -- Emit waiting event (wait..ing@token)\n' + ' rcall("PUBLISH", KEYS[1] .. "ing@" .. ARGV[11], jobId)\n' + 'end\n' + '\n' + 'return jobId .. "" -- convert to string\n', '6', 'immich_bull:search-queue:wait', 'immich_bull:search-queue:paused', 'immich_bull:search-queue:meta-paused', 'immich_bull:search-queue:id', 'immich_bull:search-queue:delayed', 'immich_bull:search-queue:priority', 'immich_bull:search-queue:', '', 'search-index-assets', '{}', '{"attempts":3,"removeOnComplete":true,"removeOnFail":false,"delay":0,"timestamp":1684864556479}', '1684864556479', '0', '0', '0', 'LPUSH', '6a94d159-4774-413f-9ba4-007d56cfd744' ] } } Node.js v18.16.0 ``` ### The OS that Immich Server is running on Kubernetes ### Version of Immich Server 1.57.1 ### Version of Immich Mobile App N/A ### Platform with the issue - [X] Server - [ ] Web - [ ] Mobile ### Your docker-compose.yml content ```YAML N/A ``` ### Your .env content ```Shell N/A ``` ### Reproduction steps ```bash I'm not sure, sorry. ``` ### Additional information _No response_
Author
Owner

@uhthomas commented on GitHub (May 23, 2023):

ah, https://github.com/dragonflydb/dragonfly/issues/782.

@uhthomas commented on GitHub (May 23, 2023): ah, https://github.com/dragonflydb/dragonfly/issues/782.
Author
Owner

@zacheryph commented on GitHub (Dec 28, 2024):

So what is the actual solution here? I need to run Dragonfly with --default_lua_flags=allow-undeclared-keys? Or... DO NOT use Dragonfly?

This ticket does nothing but reference a Dragonfly ticket. That ticket bounces around from multiple issues ranging from undeclared keys, to bad dns / app configuration / screenshots of Immich... The first solution is in the dead middle of the thread. The ending of that thread simply references a BullMQ document about changing queue names... Now as a new person, I do not know (nor should I be worried about?) that Immich uses BullMQ? Is this a Dragonfly issue? BullMQ? Immich? Do I need to change queue names? 🤷 The documentation says nothing what so ever about compatibility or requirements for using Dragonfly. There is no clear solution on this closed ticket. If the referenced ticket was ever removed for whatever reason, there is zero solution here... Can this be added to the documentation, or at bare minimum when closing tickets, put the actual solution IN the ticket.

@zacheryph commented on GitHub (Dec 28, 2024): So what is the actual solution here? I need to run Dragonfly with `--default_lua_flags=allow-undeclared-keys`? Or... _DO NOT use Dragonfly_? This ticket does nothing but reference a Dragonfly ticket. That ticket bounces around from multiple issues ranging from undeclared keys, to bad dns / app configuration / screenshots of Immich... The first solution is in the dead middle of the thread. The ending of that thread simply references a BullMQ document about changing queue names... Now as a new person, I do not know (nor should I be worried about?) that Immich uses BullMQ? Is this a Dragonfly issue? BullMQ? Immich? Do _I_ need to change queue names? 🤷 The documentation says nothing what so ever about compatibility or requirements for using Dragonfly. There is no clear _solution_ on this closed ticket. If the referenced ticket was ever removed for whatever reason, there is _zero_ solution here... Can this be added to the documentation, or at bare minimum when closing tickets, put the actual solution _IN_ the ticket.
Author
Owner

@zacheryph commented on GitHub (Dec 28, 2024):

To anyone else that stumbles upon this ticket.

If you are using Dragonfly, save yourself from reading the other 500 comment long ticket.

The solution is to add the following argument to your dragonfly instance;

--default_lua_flags=allow-undeclared-keys

@zacheryph commented on GitHub (Dec 28, 2024): To anyone else that stumbles upon this ticket. If you are using Dragonfly, save yourself from reading the other 500 comment long ticket. The solution is to add the following argument to your dragonfly instance; > `--default_lua_flags=allow-undeclared-keys`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: immich-app/immich#885