Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Sending custom commands in pipeline is not supported in Cluster mode when use Cluster Mode #758

Open
zetflo opened this issue Oct 25, 2017 · 21 comments

Comments

@zetflo
Copy link

zetflo commented Oct 25, 2017

When i use bull in redis cluster mode.

Configuration options

const opts = {
    createClient: function(type){
       return new redis.Cluster([
            ...
        ]);
    },
    prefix: '{}'
};

Create job it's worked but when i process job with queue.process,
I encounter the following error

Error: Sending custom commands in pipeline is not supported in Cluster mode.
    at Pipeline.exec (\node_modules\ioredis\lib\pipeline.js:249:19)
    at Pipeline.pipeline.exec (\node_modules\ioredis\lib\transaction.js:34:26)
    at \node_modules\bull\lib\job.js:210:18

Apparently the pipelines are not compatible with cluster mode of redis.

Can you confirm this problem?
How to use bull with a cluster redis without encountering this problem?

@manast
Copy link
Member

manast commented Oct 25, 2017

ok, seems like it is a limitation of ioredis at least. I did not now about it: redis/ioredis#536
This requires some rewrite in order to make it work in cluster mode unfortunately.

@ajwootto
Copy link

@manast we are starting to run into this. Do you know what features specifically require pipelines? Is there some subset of features we can still use without them?

@btzsoft
Copy link

btzsoft commented Apr 22, 2019

@manast I'm running in the same issue when calling job.moveToFailed(err). it's possible to do something else here? it's strange for me, because I use job.moveToCompleted() without any problems. thx!

@manast
Copy link
Member

manast commented Apr 22, 2019

@btzsoft that is because ioredis does not support multi commands using custom lua scripts, and only moveToFailed currently uses that. In order to solve this issue the method should be rewritten to not use multi, which is a bit to work to do...

@btzsoft
Copy link

btzsoft commented Apr 22, 2019

@manast oh no, do you have some plans in future to change this? if no can you give pls some hints where to take a look, maybe I will make a fork and will changes this, bcs it's really a big blocker for us. thank you for your time.

@manast
Copy link
Member

manast commented Apr 22, 2019

you can check the implementation of moveToFailed, it is quite inconvenient to not being able to use multi in this case. The other alternative is to convince the authors of ioredis to fix this issue:
redis/ioredis#536

@btzsoft
Copy link

btzsoft commented Apr 23, 2019

@manast just to better understand, why moveToFailed use multi command? and why doesn't work as moveToFinished. thx!

@manast
Copy link
Member

manast commented Apr 23, 2019

@btzsoft I think you could understand this better if you check the source code, basically it is because moveToFailed has much more functionality such as retries, updating attempts, backoffs, etc.

@joebowbeer
Copy link

joebowbeer commented Jun 2, 2020

@manast Does this mean bull is incompatible with a Redis cluster-mode-enabled cluster until ioredis is enhanced? Is there no workaround?

In the meantime, can you update the Patterns doc, which provides a (broken?) example of how to use Redis Cluster?

https://github.com/OptimalBits/bull/blob/develop/PATTERNS.md#redis-cluster

@akhil-karat
Copy link

@manast - I am facing same problem. Works with local redis instance. But in our int and prod we use Redis cluster. When a job is added to queue process fails with error 'Sending custom commands in pipeline is not supported in Cluster mode'. Then job stalls. Is there a work around for this issue? It is really urgent for us. Kindly help.

@joebowbeer
Copy link

@manast Can you confirm that this is not an issue in BullMQ?

@manast
Copy link
Member

manast commented Aug 14, 2020

@joebowbeer it is the same problem unfortunately. I was expecting ioredis to be fixed but for some reason they did not prioritize it. The alternative is to convert "moveToFailed" method in bull/bullMQ to one lua script, as you can see it is quite a bit of job, but it seems like it is the only way to solve this issue once and for all... will try to prioritize it.

@manast
Copy link
Member

manast commented Aug 14, 2020

@akhil-karat

@manast - I am facing same problem. Works with local redis instance. But in our int and prod we use Redis cluster. When a job is added to queue process fails with error 'Sending custom commands in pipeline is not supported in Cluster mode'. Then job stalls. Is there a work around for this issue? It is really urgent for us. Kindly help.

Are you sure this happens when you add the job and not when the job fails?

@joebowbeer
Copy link

@manast Thanks for prioritizing this! I repo'd the issue in BullMQ as well.

Rua-Yuki added a commit to fpm-git/bull that referenced this issue Sep 9, 2020
By using just a single ioredis custom command invocation now, rather
than a transaction including a custom command, we should have OptimalBits#758
resolved.

Slightly simplified logic (hopefully).
Rua-Yuki added a commit to fpm-git/bull that referenced this issue Sep 9, 2020
By using just a single ioredis custom command invocation now, rather
than a transaction including a custom command, we should have OptimalBits#758
resolved.

Slightly simplified logic (hopefully).
Rua-Yuki added a commit to fpm-git/bull that referenced this issue Sep 9, 2020
Affects the following scripts:
- moveToDelayed
- moveToFinished
- retryJob

Allows for the `attemptsMade`, `stacktrace` and `message` fields to be
updated through Lua scripts, rather than requiring a separate operation
(or multiple operations) to set these fields.

With the possibility of setting these fields within the context of a
single script, we avoid the need to craft a transaction containing both
HMSET and EVAL(SHA) commands to achieve atomicity. By shedding the need
for a transaction, we are able to avoid redis/ioredis#536 and thus solve
a common problem seen when targetting Redis clusters.

This isn’t necessarily an ideal means of solving this problem, given
we’re violating DRY principles by copying the same logic across
scripts. It’d be ideal if the underlying ioredis restriction was
removed (in a manner which doesn’t entail the performance cost of
resubmitting scripts each time).
Rua-Yuki added a commit to fpm-git/bull that referenced this issue Sep 9, 2020
By using just a single ioredis custom command invocation now, rather
than a transaction including a custom command, we should have OptimalBits#758
resolved.

Slightly simplified logic (hopefully).
Rua-Yuki added a commit to fpm-git/bull that referenced this issue Sep 9, 2020
Affects the following scripts:
- moveToDelayed
- moveToFinished
- retryJob

Allows for the `attemptsMade`, `stacktrace` and `message` fields to be
updated through Lua scripts, rather than requiring a separate operation
(or multiple operations) to set these fields.

With the possibility of setting these fields within the context of a
single script, we avoid the need to craft a transaction containing both
HMSET and EVAL(SHA) commands to achieve atomicity. By shedding the need
for a transaction, we are able to avoid redis/ioredis#536 and thus solve
a common problem seen when targetting Redis clusters.

This isn’t necessarily an ideal means of solving this problem, given
we’re violating DRY principles by copying the same logic across
scripts. It’d be ideal if the underlying ioredis restriction was
removed (in a manner which doesn’t entail the performance cost of
resubmitting scripts each time).
Rua-Yuki added a commit to fpm-git/bull that referenced this issue Sep 9, 2020
By using just a single ioredis custom command invocation now, rather
than a transaction including a custom command, we should have OptimalBits#758
resolved.

Slightly simplified logic (hopefully).
@Rua-Yuki
Copy link
Contributor

Rua-Yuki commented Sep 9, 2020

Super sorry for the excessive mentions all! (Was doing a bit of cleanup and of course GH has appended to this discussion for every instance of these commits.)

That said, if anyone urgently needs this working, a patch can be found in the fpm-git/bull/bug/fix-#758-redis-cluster-breakage branch.

Insert the usual "it works for us, but no warranties, etc." spiel here.

@joebowbeer
Copy link

joebowbeer commented Oct 23, 2020

@manast I think the ioredis issue is fixed in v4.19.0

@huxwfun
Copy link

huxwfun commented Dec 11, 2020

@Rua-Yuki
it appears addBulk uses pipeline as well

Job.createBulk = function(queue, jobs) {
  jobs = jobs.map(job => new Job(queue, job.name, job.data, job.opts));

  return queue
    .isReady()
    .then(() => {
      const multi = queue.client.multi();

@manast
Copy link
Member

manast commented Dec 11, 2020

Unfortunately the fix the did on ioredis breaks Bulls unit tests for repeatable jobs, so we cannot use that fix until we discover the reason for the breakage.

@Rua-Yuki
Copy link
Contributor

@Rua-Yuki
it appears addBulk uses pipeline as well

Job.createBulk = function(queue, jobs) {
  jobs = jobs.map(job => new Job(queue, job.name, job.data, job.opts));

  return queue
    .isReady()
    .then(() => {
      const multi = queue.client.multi();

@huxwfun Many thanks for bringing this to my attention! Our use case only demanded a quick fix for the issue raised here with moveToFailed, though I can definitely see about adding support for pipeline-free addBulk as well (potentially sometime early next week).

Alternatively, #1933 can be used to get the benefits of ioredis 4.19.0+, which I believe should fix this sort of issue without requiring elimination of scripts from pipelines.


Unfortunately the fix the did on ioredis breaks Bulls unit tests for repeatable jobs, so we cannot use that fix until we discover the reason for the breakage.

I've just added #1933, which seems to have the repeatable job unit tests all happy and green with ioredis 4.19.0+.

Please don't hesitate to let me know if there are any further steps I should take, or anything I might do to help out. Thanks!

@gurbaj5124871
Copy link

Is this issue resolved by updating the bull and ioredis because it seemed to fix it for me, should this issue be closed and resolved?

@manast
Copy link
Member

manast commented Mar 26, 2021

@gurbaj5124871 I am not 100% sure. Maybe somebody else from this thread could verify it before we close.

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

No branches or pull requests

9 participants