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

.map() continues execution of handlers after cancellation (using concurrency) #1622

Open
nerocrat opened this issue Oct 16, 2019 · 0 comments

Comments

@nerocrat
Copy link

  1. bluebird version: 3.7.1

  2. Node.js 10.16.0

  3. in bluebird 3.5.3 same to

If mapper returns a native promise, map() may continue to call mappers after cancellation main promise. This should not happen because concurrency is used (all mappers do not have time to start):

Promise.config({
    cancellation: true
});

function test() {
    let array_size = 100;
    let count = 0;
    let task = Promise.map(new Array(array_size), async () => {
        count++;
        if (count === array_size) console.log('all handlers were called');
        return Promise.delay(10);

    }, {concurrency: 10})

    setTimeout(() => {
        task.cancel();
    }, 10);
}

let tests_count = 100;
while (tests_count--) {
    test();
}

The console output:

all handlers were called
all handlers were called
...

This is a heisenbug, I can not reproduce it in its pure form without understanding the source code.
Correct behavior without native promises:

Promise.config({
    cancellation: true
});

function test() {
    let array_size = 100;
    let count = 0;
    let task = Promise.map(new Array(array_size), () => {
        count++;
        if (count === array_size) console.log('all handlers were called');
        return Promise.delay(10);

    }, {concurrency: 10})

    setTimeout(() => {
        task.cancel();
    }, 10);
}

let tests_count = 100;
while (tests_count--) {
    test();
}

Сonsole is empty.

in this situation, in theory, it does not matter which promise is returned by the mapper, so this behavior is not obvious to me.

I use a translator, sorry

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

1 participant