async icon indicating copy to clipboard operation
async copied to clipboard

async.series silently cancels when callback(false) is used

Open eliottkespi opened this issue 7 months ago • 1 comments

Description When using async.series with callback(false) in a task function, the series is silently canceled without running the final callback. This behavior is unexpected and undocumented, as standard error handling in async.js should still invoke the final callback when an error occurs.

Code to Reproduce

const async = require('async');

async.series([
    callback => {
        console.log(1);
        callback(false);
    },
    callback => {
        console.log(2);
        callback();
    }], () => console.log(3)
);

Expected Behavior When callback(false) is called in a task function:

Remaining task functions should be skipped (which happens correctly) The final callback should still be executed with the error value (which doesn't happen)

OR

Should be treated like null and continue to the next task

Expected output: 1 3 or 1 2 3

Actual Behavior Only 1 is printed. The final callback is never invoked and the series is silently canceled.

Version Information

async.js version: [email protected] Node.js version: v18.20.4 Platform: macOS - 15.3.2 - 24D81

eliottkespi avatar May 04 '25 12:05 eliottkespi

This is expected behavior, and is called out on the first page of the drugs under the common pitfalls section under "subtle memory leaks" as a way to cancel a flow. Maybe it should be more prominent.

Standard convention is to return null for the first callback argument. ( Or use async/await, async.series feels a bit obsolete these days )

aearly avatar May 07 '25 17:05 aearly