Skip to content

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

Closed
@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.

Activity

self-assigned this
on Jan 31, 2017
added a commit that references this issue on Jan 31, 2017
aearly

aearly commented on Jan 31, 2017

@aearly
Collaborator

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.

added a commit that references this issue on Mar 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @aearly@sunrize531

      Issue actions

        Don't call auto tasks `filter` (or any other method of Array.prototype). · Issue #1358 · caolan/async