OptimalBits / bull

Premium Queue package for handling distributed jobs and messages in NodeJS.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] constructor with options does not destructure redis property if it is a string

Shinigami92 opened this issue · comments

Description

When passing redis connection as options object but it is a url, the url will not destructed

bull/lib/queue.js

Lines 85 to 129 in 4d197e8

const Queue = function Queue(name, url, opts) {
if (!(this instanceof Queue)) {
return new Queue(name, url, opts);
}
if (_.isString(url)) {
const clonedOpts = _.cloneDeep(opts || {});
opts = {
...clonedOpts,
redis: {
...redisOptsFromUrl(url),
...clonedOpts.redis
}
};
} else {
opts = _.cloneDeep(url || {});
}
if (!_.isObject(opts)) {
throw TypeError('Options must be a valid object');
}
if (opts.limiter) {
if (opts.limiter.max && opts.limiter.duration) {
this.limiter = opts.limiter;
} else {
throw new TypeError('Limiter requires `max` and `duration` options');
}
}
if (opts.defaultJobOptions) {
this.defaultJobOptions = opts.defaultJobOptions;
}
this.name = name;
this.token = uuid.v4();
opts.redis = {
enableReadyCheck: false,
...opts.redis
};
_.defaults(opts.redis, {
port: 6379,
host: '127.0.0.1',

If not passed as string, the if in line 90 will be omitted and then it be ignored via line 129 because this takes precedents over string

Minimal, Working Test code to reproduce the issue.

import Queue from 'bull';

new Queue<any>('name', { redis: 'redis://my.host/6379' }); // results in 127.0.0.1 ❌

new Queue<any>('name', 'redis://my.host/6379'); // results in my.host ✅

Bull version

4.11.3

Additional information

This took me around 4h to find out...

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Please only mark issues and PRs as stale if there are reasons why e.g. they couldn't get reviewed or merged.
This behavior of marking issues as stale is not helping anyone.

🎉 This issue has been resolved in version 4.11.5 🎉

The release is available on:

Your semantic-release bot 📦🚀