Skip to content

Unexpected upward cancellation propagation #1459

@jsor

Description

@jsor

I've discovered the following behaviour which i'm unsure whether that is correct or a bug (tested with v3.0.0 and latest v3.5.0).

var promise1 = new Promise(function(resolve, reject, onCancel) {
    onCancel(function() {
        console.log("onCancel promise1");
    });
});

var promise2 = new Promise(function(resolve, reject, onCancel) {
    resolve(promise1);
    onCancel(function() {
        console.log("onCancel promise2");
    });
});

var promise3 = new Promise(function(resolve, reject, onCancel) {
    resolve(promise2);
    onCancel(function() {
        console.log("onCancel promise3");
    });
});

promise3.cancel();

I've expected the output to be

onCancel promise3
onCancel promise2
onCancel promise1

but it's actually

onCancel promise3
onCancel promise1

Bluebird is invoking the cancel callback on the root promise1 only, but not on the intermediary promise2. Is this the expected behaviour?

I've seen there is a similar test case, but it's calling finally() for all promises in between.

specify("cancels the followee, calling all callbacks and finally handlers", function() {
var called = 0;
var finalled = 0;
var promise = new Promise(function(_, __, onCancel) {
onCancel(function() {
called++;
});
}).lastly(function() {
finalled++;
});
var promise2 = new Promise(function(resolve, reject, onCancel) {
resolve(promise);
onCancel(function() {
called++;
});
}).lastly(function() {
finalled++;
});
var promise3 = new Promise(function(resolve, reject, onCancel) {
resolve(promise2);
onCancel(function() {
called++;
});
}).lastly(function() {
finalled++;
});
promise3.cancel();
return awaitLateQueue(function() {
assert.equal(3, called);
assert.equal(3, finalled);
});
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions