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

Don't call auto tasks filter (or any other method of Array.prototype). #1358

Closed
sunrize531 opened this issue Jan 26, 2017 · 1 comment
Closed
Assignees
Labels

Comments

@sunrize531
Copy link

sunrize531 commented Jan 26, 2017

What version of async are you using?
2.1.4

Which environment did the issue occur in (Node version/browser version)
Node 6.9.4

What did you do? Please include a minimal reproducable case illustrating issue.

const _ = require('lodash');
const async = require('async');

async.auto({
	'one': function (next) {
		_.defer(function () {
			console.info('Error');
			next('Something bad happened here');
		});
	},
	'filter': function (next) {
		_.delay(function () {
			console.info('Fine');
			next(null, 'All fine here though');
		}, 1000);
	},
	'finally': ['one', 'filter', function (a, next) {
		_.defer(next);
	}]
}, function (err, auto) {
	if (err) {
		console.error(`Caught: ${err}`);
	} else {
		console.info(auto);
	}
});

What did you expect to happen?
Logs error but doesn't raise exception.

What was the actual result?

TypeError: fn is not a function
    at C:\somewhere\node_modules\async\dist\async.js:1594:13
    at arrayEach (C:\somewhere\node_modules\async\dist\async.js:1298:9)
    at taskComplete (C:\somewhere\node_modules\async\dist\async.js:1593:9)
    at C:\somewhere\node_modules\async\dist\async.js:1619:17
    at apply (C:\somewhere\node_modules\async\dist\async.js:21:25)
    at C:\somewhere\node_modules\async\dist\async.js:56:12
    at breakLoop (C:\somewhere\node_modules\async\dist\async.js:840:16)
    ... cut ...

This is because of:

  1. listeners variable initially declared as an object, being transformed to array at some point (line 1614) for some reason, which is a bad idea in general.
  2. Even if it was an object at that point, it doesn't guarantee anything, without additional hasOwnProperty check. Someone might as well call task hasOwnProperty.
@aearly aearly self-assigned this Jan 31, 2017
@aearly aearly added the bug label Jan 31, 2017
aearly added a commit that referenced this issue Jan 31, 2017
@aearly
Copy link
Collaborator

aearly commented Jan 31, 2017

I have a fix for this. I couldn't reproduce the error in a test case for some reason, but I see exactly how it is caused.

@aearly aearly closed this as completed Jan 31, 2017
hargasinski added a commit to hargasinski/async that referenced this issue Mar 28, 2017
generated from commit 8903d46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants