Skip to content

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

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

Open
eliottkespi opened this issue May 4, 2025 · 1 comment
Open

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

eliottkespi opened this issue May 4, 2025 · 1 comment

Comments

@eliottkespi
Copy link

eliottkespi commented May 4, 2025

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

@aearly
Copy link
Collaborator

aearly commented May 7, 2025

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 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants