Bull: removeJobs function returns redis error

Created on 11 Jun 2020  路  21Comments  路  Source: OptimalBits/bull

Description

Not sure if Bull bug or something else.
I'm trying to call queue.removeJobs(pattern) with pattern = "12345*" but it returns:

ERR Error running script (call to f_531d166ed840471540203603686123486730c4d5): @user_script:38: @user_script: 38: Write commands not allowed after non deterministic commands

Bull version

v3.14.0

cannot reproduce need investigation

Most helpful comment

Can you try with redis 5.0.3 instead? 3.x is pretty old actually, could be an issue with redis itself.

This error is gone after updating Redis version to 5.x.

All 21 comments

hmm, that strange, are you running in a master-slave setup?

No

can you provide a complete example that reproduces the issue?

I get the same issue. Here is an example script:

require('dotenv').config();
const Bull = require('bull');
const uuid = require('uuid/v4');

const isLocal = process.env.NODE_ENV === 'local';

const config = {
  redis: {
    host: process.env.REDIS_HOST || '127.0.0.1',
    port: process.env.REDIS_PORT || 6379,
    password: process.env.REDIS_PASSWORD || '',
    ...!isLocal && { tls: {} },
    db: 2
  }
}

const queue = new Bull('test-queue', config);

const processor = async data => {
  console.log('processing job...'), data;
  throw new Error('Oh no!');
}

queue.process(processor);

queue.on('failed', async () => {
  await queue.removeJobs('test-queue*');
  console.log('queue deleted OK');
});

queue.add({ foo: 'bar' }, {
  jobId: `test-queue.${uuid()}`
});

On my local machine this works, however on AWS with Elasticache I get the error described above.

We are also using AWS Elasticache.

Same thing here :(
image

ReplyError: ERR Error running script (call to f_531d166ed840471540203603686123486730c4d5): @user_script:38: @user_script: 38: Write commands not allowed after non deterministic commands

Error on removeJobs, not on getJob for sure. Job is completed, not processing.

Redis is used ONLY for Bull.

Oh, easily removed with job.remove(). So I don't need any help, but if you wish you still could solve this issue.

Which version of elasticache are you using? I use remove with pattern in elasticache without any issues so far.

@james-siteclick is your intent to delete all the jobs in a queue with the above pattern? Can you try with

 await queue.removeJobs('*');

instead? you do not need to specify the "prefix" of the queue.

@denysaw did you get the above error locally also or only on elasticache?

@denysaw did you get the above error locally also or only on elasticache?

Locally. Today also tried to remove all jobs on start (as empty() does nothing): await queue.removeJobs('*'); getting same error.

Thank God, I thought of such workaround:

for (let job of await queue.getJobs()) {
    await job.moveToFailed({message: 'Canceled'}, true);
    await job.remove();
}

Worx. But I would be glad to replace this *code with working empty() or removeJobs() ;)

@denysaw empty works just fine, removes all the jobs that are waiting or delayed.

@denysaw whats your version of redis?

Strange. I started today with empty(), but getJobs() shown me job I started yesterday :)
Redis is 3.0.504

Can you try with redis 5.0.3 instead? 3.x is pretty old actually, could be an issue with redis itself.

Can't right now. Will try in some days only. Gonna let you know ;)

@james-siteclick is your intent to delete all the jobs in a queue with the above pattern? Can you try with

 await queue.removeJobs('*');

instead? you do not need to specify the "prefix" of the queue.

@manast thanks for your reply. In our use case we have a parent job with an ID something like:


And this creates some other jobs:

parent-job-id.child-job-id-a
parent-job-id.child-job-id-b
...

We are trying to delete only the jobs that were created by this particular parent job, so we are doing something like:

queue.removeJobs('parent-job-id.*');

I simplified this a bit for the code example.

@james-siteclick that should work. Could you just verify that your elasticache in AWS is running version 5.x ? I have services in production where we use remove with pattern in AWS and it is working, so I am a bit puzzled by this. The error itself does not make so much sense, since the call is deterministic.

Can you try with redis 5.0.3 instead? 3.x is pretty old actually, could be an issue with redis itself.

This error is gone after updating Redis version to 5.x.

Getting the same error. Seems like this error happens when a pattern matches a job.
Versions:

OS: Win10
Redis: 3.0.2
Bull: 3.18.0

You can replicate the error with the following code:

(async () => {
await queue.add({}, {jobId: 'a'});
await queue.removeJobs('a');
)();
Was this page helpful?
0 / 5 - 0 ratings