Skip to content

Error: NOSCRIPT No matching script. Please use EVAL. #27

Closed

Description

@davisford

I'm opening a new issue - related to #24 b/c 24 is closed, but unresolved, as far as I can tell.

I'm trying to migrate from kue to bee-queue, and when I start up the app, it throws this error:

Error: NOSCRIPT No matching script. Please use EVAL.
    at ReplyParser.<anonymous> (/Users/davis/git/warehouse-web/node_modules/bee-queue/node_modules/redis/index.js:320:31)
    at ReplyParser.emit (events.js:107:17)
    at ReplyParser.send_error (/Users/davis/git/warehouse-web/node_modules/bee-queue/node_modules/redis/lib/parser/javascript.js:298:10)
    at ReplyParser.execute (/Users/davis/git/warehouse-web/node_modules/bee-queue/node_modules/redis/lib/parser/javascript.js:183:22)
    at RedisClient.on_data (/Users/davis/git/warehouse-web/node_modules/bee-queue/node_modules/redis/index.js:550:27)
    at Socket.<anonymous> (/Users/davis/git/warehouse-web/node_modules/bee-queue/node_modules/redis/index.js:105:14)
    at Socket.emit (events.js:107:17)
    at readableAddChunk (_stream_readable.js:163:16)
    at Socket.Readable.push (_stream_readable.js:126:10)
    at TCP.onread (net.js:538:20) +2ms

...which I understand to mean Redis is saying the Lua scripts are not cached, so they'll need to be EVAL'd instead. This should be true since I'm just trying bee-queue for the first time.

However, I also pulled the proposed fix from #24 commit here

$npm ls --depth=0 | grep bee
npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
├── [email protected] (git+ssh://[email protected]/mllongze/bee-queue.git#8cefcb25b27c23840ca668578d3ae4bcdf4ebcd3)

And when I run with that, I hit the same error. It does not resolve it for me. I'm running Redis 3.0.3 on localhost for development.

Activity

  1. davisford commented on Dec 8, 2015

    @davisford
    Author

    I tried to load the scripts manually:

    $cat addJob.lua | redis-cli -x script load
    "acda255b02f152d22a0b0dab8495514c47d97815"
    
    $cat checkStalledJobs.lua | redis-cli -x script load
    "c0ca21d4864dbc3e94050afbeab36877df17122d"
    
    $cat removeJob.lua | redis-cli -x script load
    "2d16511dd368b5b1a99d41eac4e6c759b0689941"
    

    scripts are loaded:

    127.0.0.1:6379> script exists acda255b02f152d22a0b0dab8495514c47d97815
    1) (integer) 1
    127.0.0.1:6379> script exists c0ca21d4864dbc3e94050afbeab36877df17122d
    1) (integer) 1
    127.0.0.1:6379> script exists 2d16511dd368b5b1a99d41eac4e6c759b0689941
    1) (integer) 1
    

    ...but when I run, same error. Do those sha1 match?

  2. davisford commented on Dec 8, 2015

    @davisford
    Author

    Executing this test script indicates the shas are the same:

    var fs = require('fs');
    var crypto = require('crypto');
    var path = require('path');
    
    var scripts = {};
    var shas = {};
    
    var readScripts = function () {
      fs.readdirSync(__dirname)
        .filter(function (file) {
          return file.slice(-4) === '.lua';
        }).forEach(function (file) {
          var hash = crypto.createHash('sha1');
          var key = file.slice(0, -4);
          scripts[key] = fs.readFileSync(path.join(__dirname, file)).toString();
          hash.update(scripts[key]);
          shas[key] = hash.digest('hex');
        });
      console.log('shas: ', shas);
    };
    
    readScripts();

    Outputs:

    shas:  { addJob: 'acda255b02f152d22a0b0dab8495514c47d97815',
      checkStalledJobs: 'c0ca21d4864dbc3e94050afbeab36877df17122d',
      removeJob: '2d16511dd368b5b1a99d41eac4e6c759b0689941' }
    

    What am I missing?

  3. davisford commented on Dec 8, 2015

    @davisford
    Author

    OK, after I uninstalled @mllongze fork, and then re-installed the last official npm release, and having pre-installed the scripts directly via redis-cli, it seems to have gotten past the issue.

  4. LewisJEllis commented on Dec 8, 2015

    @LewisJEllis
    Member

    Hmm, this is a bit strange. Are you waiting for the ready queue event? It's possible to beat the caching check to the punch by not waiting for that event, but even if you're not waiting for that event, I wouldn't expect you to run into this problem if you've manually cached the scripts. There's a procedure to check if the scripts are cached on first connection, and to cache them if they're missing (and only if they're missing, so you shouldn't be running into any sort of "tried doing something halfway through the cache repopulation" issue). I'm a bit puzzled because the only time I've run into the NOSCRIPT error myself has been after a restart of Redis while Node is still running (as was the case in #24); I've never run into it on a clean startup of Node.

    The Lua script caching being something I haven't seen other node/redis task queues utilize, of course I run into troubles with it. It seems like it would be reasonable to automatically queue commands until that ready event fires, so as to avoid some situations like this, but I'm not convinced that that would solve whatever's happening here. I'll have to do some investigation; I haven't used bee-queue on Redis 3.x yet, but hopefully that isn't the issue.

  5. LewisJEllis commented on Dec 8, 2015

    @LewisJEllis
    Member

    Also, I just verified that those three cache shas are the same as on my production instances of bee-queue (or, well, instances of Redis that back bee-queue).

  6. LewisJEllis commented on Dec 8, 2015

    @LewisJEllis
    Member

    Your steps that ended up fixing it make me wonder if that fix to #24 introduced something strange. I'll have to look at it more closely. Everything modulo that fork can be explained by the "beating the caching procedure to the punch" bit, but for it to continue failing after manually caching them is puzzling. It sounds like it only continued to fail after manual caching if you were on that fork, though, correct?

    I'm wondering if the following two sequences play out as described:
    With [email protected]: wipe redis, start node -> NOSCRIPT error, manually cache, start node -> works?
    With #24 fork: wipe redis, start node -> NOSCRIPT error, manually cache, start node -> still NOSCRIPT error?

    I can't verify this right now, but will try it tonight.

  7. davisford commented on Dec 8, 2015

    @davisford
    Author

    Yes, after manually installing them in the cache, it continued to fail with that fork. When I switched back to the latest official release, it started working again.

    I wrote that test script above and just copied your source that creates client side hashes and printed them, and also verified they are the same as what is in redis.

  8. LewisJEllis commented on Dec 8, 2015

    @LewisJEllis
    Member

    Okay, great, thanks for confirming. Also, are you waiting for the ready event? If not, then I think I have a hypothesis for what's going on. There are probably two things to do:

    • Implement the fix to Redis Server Crash reconnect error? #24 but be careful not to introduce a new bug (whatever you seem to have encountered after manually caching with the fork) in doing so
    • Automatically queue commands issued before the ready event, so as to avoid NOSCRIPT errors in certain situations on startup (what I think you encountered at the beginning of all this)
  9. davisford commented on Dec 8, 2015

    @davisford
    Author

    Ah, I had a callback for the ready event, but I didn't actually wait for it until the rest of the stuff bootstraps itself. So, yea, that may have a big part of the issue?

  10. davisford commented on Dec 10, 2015

    @davisford
    Author

    I've done some further testing, and it seems if you wait for the ready event before you try to call Queue.process or Queue.createJob it works as expected. If you prematurely use those APIs, it seems to fail with this error.

    I have several different producer / consumer scripts, so I just need to go through them all and ensure each one waits for ready before trying to use the Queue api.

    Seems like a doc fix would be sufficient?

  11. davisford commented on Dec 10, 2015

    @davisford
    Author

    Yea, I got tricked by another one. I was doing something like this:

    var queue;
    
    // get queue
    module.exports = function (done) {
      if (queue) { return queue; }
    
      queue = new Queue('foo', { /* params */ });
      queue.on('ready', function () {
          done();
      });
      // this line can throw EVALSHA/EVAL error if scripts aren't loaded, too
      queue.checkStalledJobs(5000);
    }
  12. LewisJEllis commented on Dec 10, 2015

    @LewisJEllis
    Member

    Yep, that all seems like expected behavior. The ready event is documented here, but I do think it's a bit tucked away and possibly downplayed too much relative to how much of a caveat it can be. I think the plan to have the library automatically queue any commands called before the ready event should avoid these situations altogether. I've opened an issue to track that feature, which should come this weekend.

  13. skeggse commented on Aug 9, 2017

    @skeggse
    Member

    As of 1.0.0, all Queue internals should wait for the scripts to load prior to issuing commands that use said scripts.

  14. yss14 commented on Nov 6, 2018

    @yss14
    Contributor

    So what's the solution for this problem? Had this problem a few times in the last weeks on our production instances which all rely on bee-queue.

  15. AmeyMore98 commented on Dec 18, 2022

    @AmeyMore98

    Hey, any fix for this?

  16. AmeyMore98 commented on Dec 18, 2022

    @AmeyMore98

    In my case, the problem appears to be caused by Redis Cluster. When the command 'loadScriptIfMissing' is executed, half of the commands are executed on one shard and the other half on another. As a result, the shards do not have all of the scripts loaded, resulting in 'EVALSHA' failing. I figured this out by running the MONITOR command on all shards.

    Because I am not a Redis expert, can someone please confirm this hypothesis and provide a solution?
    Thanks

  17. compwright commented on Dec 19, 2022

    @compwright
    Collaborator

    @AmeyMore98 that seems like a somewhat different error than was reported here, please open a new issue on the cluster issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions