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

Cancellation does not clear timeout #926

Closed
suprememoocow opened this issue Dec 18, 2015 · 1 comment
Closed

Cancellation does not clear timeout #926

suprememoocow opened this issue Dec 18, 2015 · 1 comment

Comments

@suprememoocow
Copy link

Using bluebird@3.1.1, I've noticed that processes will not shutdown until the timeout has triggered, even if the promise is cancelled.

In this example, I would have expected the process to shutdown after roughly 1s, but the process will take about 10 seconds before shutting down, due to the setTimeout reference called from promise.timeout still being active.

var Promise = require('bluebird');
Promise.config({ cancellation: true });

process.on('exit', function() {
  console.log(new Date(), 'Process exiting');
});

console.log(new Date(), 'Starting');  
var p = new Promise(function(resolve, reject, onCancel) {
    onCancel(function() {
      console.log(new Date(), 'Cancelled');
    });
  })
  .timeout(10000);

// Wait 1s, the
setTimeout(function() {
  console.log(new Date(), 'Cancelling promise');
  p.cancel();
}, 1000);

The output looks like this

Fri Dec 18 2015 11:22:00 GMT+0000 (GMT) 'Starting'
Fri Dec 18 2015 11:22:01 GMT+0000 (GMT) 'Cancelling promise'
Fri Dec 18 2015 11:22:01 GMT+0000 (GMT) 'Cancelled' 
Fri Dec 18 2015 11:22:10 GMT+0000 (GMT) 'Process exiting'

Notice the 10 second delay on the last log line.

@suprememoocow
Copy link
Author

👍 thank you for this fix and thanks once again for an incredible library!

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

No branches or pull requests

2 participants