Skip to content

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

@sunrize531

Description

@sunrize531

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.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions