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

Size discrepancy between queue.workersList().length and queue.running() #1428

Closed
dstibrany opened this issue Jun 6, 2017 · 1 comment
Closed

Comments

@dstibrany
Copy link

What version of async are you using?
2.4.1
Which environment did the issue occur in (Node version/browser version)
Node v4.6.0
What did you expect to happen?
queue.workersList().length should be the same size as queue.running()
What was the actual result?
They sometimes are not the same length.

I'm observing a discrepancy between queue.workersList().length and queue.running(). It looks like lib/internal/queue.js line 60 may be the culprit. Shouldn't we always be splicing exactly one element here instead of potentially many elements. So replacing:

workersList.splice(index)

with

workersList.splice(index, 1)

@hargasinski
Copy link
Collaborator

Hey Dave, thanks for the report!

I believe you are right. According to the QueueObject docs workersList() should return

the array of items currently being processed.

which is not the case right now:

var q = async.queue(function(task, cb) {
    async.setImmediate(function() {
        console.log(`Processing ${task.name}`);
        console.log(q.workersList());
        console.log(q.running());
        cb();
    });
}, 2);

q.push({name: 'foo'});
q.push({name: 'bar'});
q.push({name: 'baz'});

gives

Processing foo
[ { data: { name: 'foo' },
    callback: [Function: noop],
    next: null,
    prev: null },
  { data: { name: 'bar' },
    callback: [Function: noop],
    prev: null,
    next: null } ]
2
Processing bar
[ { data: { name: 'baz' },
    callback: [Function: noop],
    prev: null,
    next: null } ]
2
Processing baz
[ { data: { name: 'baz' },
    callback: [Function: noop],
    prev: null,
    next: null } ]
1

as opposed to the expected (with workersList.splice(index, 1)):

Processing foo
[ { data: { name: 'foo' },
    callback: [Function: noop],
    next: null,
    prev: null },
  { data: { name: 'bar' },
    callback: [Function: noop],
    prev: null,
    next: null } ]
2
Processing bar
[ { data: { name: 'bar' },
    callback: [Function: noop],
    prev: null,
    next: null },
  { data: { name: 'baz' },
    callback: [Function: noop],
    prev: null,
    next: null } ]
2
Processing baz
[ { data: { name: 'baz' },
    callback: [Function: noop],
    prev: null,
    next: null } ]
1

Thanks for debugging the issue.

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

2 participants